1 // Copyright (C) 2003, 2008 Fernando Luis Cacciola Carballal.
2 // Copyright (C) 2015 Andrzej Krzemienski.
4 // Use, modification, and distribution is subject to the Boost Software
5 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // See http://www.boost.org/libs/optional for documentation.
10 // You are welcome to contact the author at:
13 #ifndef BOOST_OPTIONAL_DETAIL_OPTIONAL_SWAP_AJK_28JAN2015_HPP
14 #define BOOST_OPTIONAL_DETAIL_OPTIONAL_SWAP_AJK_28JAN2015_HPP
16 #include <boost/core/swap.hpp>
17 #include <boost/optional/optional_fwd.hpp>
21 namespace optional_detail {
23 template <bool use_default_constructor> struct swap_selector;
26 struct swap_selector<true>
29 static void optional_swap ( optional<T>& x, optional<T>& y )
31 const bool hasX = !!x;
32 const bool hasY = !!y;
42 // Boost.Utility.Swap will take care of ADL and workarounds for broken compilers
43 boost::swap(x.get(), y.get());
52 #ifdef BOOST_OPTIONAL_DETAIL_MOVE
53 # undef BOOST_OPTIONAL_DETAIL_MOVE
56 #ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
57 # define BOOST_OPTIONAL_DETAIL_MOVE(EXPR_) boost::move(EXPR_)
59 # define BOOST_OPTIONAL_DETAIL_MOVE(EXPR_) EXPR_
63 struct swap_selector<false>
66 static void optional_swap ( optional<T>& x, optional<T>& y )
67 //BOOST_NOEXCEPT_IF(::boost::is_nothrow_move_constructible<T>::value && BOOST_NOEXCEPT_EXPR(boost::swap(*x, *y)))
77 y = BOOST_OPTIONAL_DETAIL_MOVE(*x);
85 x = BOOST_OPTIONAL_DETAIL_MOVE(*y);
92 } // namespace optional_detail
94 #if (!defined BOOST_NO_CXX11_RVALUE_REFERENCES) && (!defined BOOST_CONFIG_RESTORE_OBSOLETE_SWAP_IMPLEMENTATION)
97 struct optional_swap_should_use_default_constructor : boost::false_type {} ;
102 struct optional_swap_should_use_default_constructor : has_nothrow_default_constructor<T> {} ;
107 inline void swap ( optional<T>& x, optional<T>& y )
108 //BOOST_NOEXCEPT_IF(::boost::is_nothrow_move_constructible<T>::value && BOOST_NOEXCEPT_EXPR(boost::swap(*x, *y)))
110 optional_detail::swap_selector<optional_swap_should_use_default_constructor<T>::value>::optional_swap(x, y);
115 #undef BOOST_OPTIONAL_DETAIL_MOVE
117 #endif // header guard