Fix polynomial.hpp deprecated-copy warnings #111
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixed Deprecated Copy Constructor Warning in
polynomial.hpp
Issue Description
The
boost/random/detail/polynomial.hpp
triggers compiler warnings related to a deprecated implicit copy constructor:This warning occurs in C++11 and later standards when a class has a user-declared copy assignment operator but no user-declared copy constructor.
Cause
The
reference
class has a user-declared copy assignment operator:However, this reference class lacks an explicitly declared copy constructor.
Backwards-Compatible Fix
To ensure maximum compatibility with various compiler versions, including older ones, we've implemented the following changes:
Explicitly defined a copy constructor that performs a member-wise copy. This silences the deprecation warning while maintaining the original behavior:
cpp reference(const reference& other) : _value(other._value), _idx(other._idx) {}
Omitted the move constructor, ensuring compatibility with pre-C++11 compilers while not affecting functionality. In C++11 and later, moves will be performed as copies, maintaining original behavior.
Impact of the Fix
This fix resolves the compiler warnings without changing the functionality of the
reference
class.The fix is backwards-compatible and should not introduce any behavioral changes in existing code.
Conclusion
This update brings the
polynomial.hpp
file in line with current C++ standards and best practices. It eliminates deprecation warnings while maintaining existing functionality.