Relax std::move_if_noexcept for std::pair
François Dumont
frs.dumont@gmail.com
Thu Dec 20 06:29:00 GMT 2018
Hi
   I eventually find out what was the problem with the
std::move_if_noexcept within associative containers.
   The std::pair move default constructor might not move both first
and second member. If any is not moveable it will just copy it. And then
the noexcept qualification of the copy constructor will participate in
the noexcept qualification of the std::pair move constructor. So
std::move_if_noexcept can eventually decide to not use move because a
_copy_ constructor not noexcept qualified.
   This is why I am partially specializing __move_if_noexcept_cond. As
there doesn't seem to exist any Standard meta function to find out if
move will take place I resort using std::is_const as in this case for
sure the compiler won't call the move constructor.
   Note that I find __move_if_noexcept_cond very counter-intuitive
cause it says if the move semantic should _not_ be used.
   I am submitting this now cause it might be consider as a bug even
if the end result is just that it pessimizes the occasion to use move
semantic rather than copy.
   * include/bits/stl_pair.h (__move_if_noexcept_cond<pair<>>): New
   partial specialization.
   * testsuite/20_util/move_if_noexcept/1.cc (test02): New.
   * testsuite/23_containers/unordered_map/allocator/move_assign.cc
   (test03): New.
   Tested under Linux x86_64 normal mode.
François
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pair_move_if_noexcept.patch
Type: text/x-patch
Size: 5278 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20181220/3438f9e2/attachment.bin>
More information about the Libstdc++
mailing list