Explicitly default operator= for Vec<T, n>#14934
Merged
opencv-pushbot merged 1 commit intoopencv:3.4from Jun 30, 2019
Merged
Conversation
alalek
reviewed
Jun 29, 2019
| const _Tp& operator ()(int i) const; | ||
| _Tp& operator ()(int i); | ||
|
|
||
| constexpr Vec<_Tp, cn>& operator=(const Vec<_Tp, cn>& rhs) = default; |
Member
There was a problem hiding this comment.
#ifdef CV_CXX11(due= default)- Do we really need
constexprhere? if so, please useCV_CONSTEXPRinstead. IMHO, it is better to removecontexprhere completely (see Windows builder warnings) - What is about move assignment operator (
Vec<_Tp, cn>&& rhs)?
Contributor
Author
There was a problem hiding this comment.
According to:
http://eel.is/c++draft/dcl.fct.def.default#3
If a function is explicitly defaulted on its first declaration, it is implicitly considered to be constexpr if the implicit declaration would be.
As it is implicit constexpr, the "constexpr" can be removed without loss for the relevant cases (you can of course have a Vec<Foo, 1>, where Foo would lead to non-constexpr).
move assignments and constructors are implicitly "deleted" already, as there is a user-declared copy constructor. Both would be pointless for an array on the stack anyway (you can not efficiently move/swap these, not anymore than a memcpy would do).
Due to the explicitly declared copy constructor Vec<T, n>::Vec(Vec <T,n>&) GCC 9 warns if there is no assignment operator, as having one typically requires the other (rule-of-three, constructor/desctructor/assginment). As the values are just a plain array the default assignment operator does the right thing. Tell the compiler explicitly to default it. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
35e6a22 to
e9a2e66
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Due to the explicitly declared copy constructor Vec<T, n>::Vec(Vec <T,n>&)
GCC 9 warns if there is no assignment operator, as having one typically
requires the other (rule-of-three, constructor/desctructor/assginment).
As the values are just a plain array the default assignment operator does
the right thing. Tell the compiler explicitly to default it.
resolves #14933