Use std::move (C++11) in map and set adaptors where possible. #279
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.
Using std::move for map/set is potentially more efficient (depending on the type), but also allows converting to move-only types where previously the types had to have a copy constructor.
For insert(), moving will actually prevent the copy if possible. This is the important part of the patch.
swap() is very similar to a move assignment, but needs to ensure that the
tmp
variable will afterwards contain the original contents of the targetv
variable, which we don't care about but requires a temporary variable for three-way swapping anyway, so it's a bit less optimal.I made the moves dependent on the standard macro for C++11 since there's no need to depend on any msgpack defines in these cases, and in the cpp11/ directory there are no #ifdefs. I did not adapt any code in the tr1/ directory since the TR1 types did not have move constructors or move assignment operators anyway (move got introduced very late in the standardization process).