[Core] Added move operations to class Flags
#13952
Merged
+10
−13
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.
📝 Description
The aim of this PR is to make class
Flagsmoveable. So far, it wasn't, since it explicitly defined the destructor and the copy operations (i.e. the copy constructor and the copy assignment operator). As a result, the move operations are not automatically supplied by the compiler (and thus we miss out on an optimization opportunity, since "moves" will become copies). For those who need a refresher on this topic, Howard Hinnant gives a very clear explanation in one of his presentations. In particular, starting from 13:21 he explains under which circumstances special members are provided by the compiler (and when they are not).Since
Flagsis the base class of many other classes, those classes in turn are non-moveable, too. However, we don't see a fundamental objection against makingFlagsmoveable. In fact, when it becomes moveable, other classes can be made moveable as well. To limit the scope of this PR as much as possible, we haven't touched any other classes. We may want to do that in follow-up PRs.🆕 Changelog
= defaultfor special member functions (i.e. the default constructor, the (virtual) destructor, the copy constructor, and the copy assignment operator) rather than writing down the code that the compiler can generate for us. Note that we are using the "Rule of Five" here, since we need a virtual destructor. And, as Howard Hinnant explains, when a destructor is user-declared, the move operations (i.e. the move constructor and the move assignment operator) won't be declared. That's why we explicitly declare them here (including our request to the compiler to provide default implementations for them).mIsDefinedandmFlagsare initialized in-class, and they are explicitly default-constructed. See this rule in the C++ Core Guidelines of why this is a good idea (the text below has been quoted from this rule):