From 4e7405a2339b0534c7975c850714174ba3fcfca1 Mon Sep 17 00:00:00 2001 From: Andrzej Krzemienski Date: Mon, 18 May 2015 16:51:12 +0200 Subject: [PATCH] Sane swap() for rvalue-aware compilers When we detect that compiler supports rvalue references, we implement swap() in term of moves (as intuition suggests). Otherwise we fall back to old tricks with default constructor+swap --- include/boost/optional/optional.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/boost/optional/optional.hpp b/include/boost/optional/optional.hpp index fd7cf73..f059e2e 100644 --- a/include/boost/optional/optional.hpp +++ b/include/boost/optional/optional.hpp @@ -1543,9 +1543,18 @@ struct swap_selector } // namespace optional_detail +#if (!defined BOOST_NO_CXX11_RVALUE_REFERENCES) && (!defined BOOST_CONFIG_RESTORE_OBSOLETE_SWAP_IMPLEMENTATION) + +template +struct optional_swap_should_use_default_constructor : boost::false_type {} ; + +#else + template struct optional_swap_should_use_default_constructor : has_nothrow_default_constructor {} ; +#endif //BOOST_NO_CXX11_RVALUE_REFERENCES + template inline void swap ( optional& x, optional& y ) //BOOST_NOEXCEPT_IF(::boost::is_nothrow_move_constructible::value && BOOST_NOEXCEPT_EXPR(boost::swap(*x, *y))) {