File indexing completed on 2025-01-18 09:43:20
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef BOOST_OPTIONAL_DETAIL_OPTIONAL_SWAP_AJK_28JAN2015_HPP
0014 #define BOOST_OPTIONAL_DETAIL_OPTIONAL_SWAP_AJK_28JAN2015_HPP
0015
0016 #include <boost/core/invoke_swap.hpp>
0017 #include <boost/optional/optional_fwd.hpp>
0018
0019 namespace boost {
0020
0021 namespace optional_detail {
0022
0023 template <bool use_default_constructor> struct swap_selector;
0024
0025 template <>
0026 struct swap_selector<true>
0027 {
0028 template <class T>
0029 static void optional_swap ( optional<T>& x, optional<T>& y )
0030 {
0031 const bool hasX = !!x;
0032 const bool hasY = !!y;
0033
0034 if ( !hasX && !hasY )
0035 return;
0036
0037 if( !hasX )
0038 x.emplace();
0039 else if ( !hasY )
0040 y.emplace();
0041
0042
0043 boost::core::invoke_swap(x.get(), y.get());
0044
0045 if( !hasX )
0046 y = boost::none ;
0047 else if( !hasY )
0048 x = boost::none ;
0049 }
0050 };
0051
0052 #ifdef BOOST_OPTIONAL_DETAIL_MOVE
0053 # undef BOOST_OPTIONAL_DETAIL_MOVE
0054 #endif
0055
0056 #ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
0057 # define BOOST_OPTIONAL_DETAIL_MOVE(EXPR_) boost::move(EXPR_)
0058 #else
0059 # define BOOST_OPTIONAL_DETAIL_MOVE(EXPR_) EXPR_
0060 #endif
0061
0062 template <>
0063 struct swap_selector<false>
0064 {
0065 template <class T>
0066 static void optional_swap ( optional<T>& x, optional<T>& y )
0067
0068 {
0069 if (x)
0070 {
0071 if (y)
0072 {
0073 boost::core::invoke_swap(*x, *y);
0074 }
0075 else
0076 {
0077 y = BOOST_OPTIONAL_DETAIL_MOVE(*x);
0078 x = boost::none;
0079 }
0080 }
0081 else
0082 {
0083 if (y)
0084 {
0085 x = BOOST_OPTIONAL_DETAIL_MOVE(*y);
0086 y = boost::none;
0087 }
0088 }
0089 }
0090 };
0091
0092 }
0093
0094 #if (!defined BOOST_NO_CXX11_RVALUE_REFERENCES) && (!defined BOOST_CONFIG_RESTORE_OBSOLETE_SWAP_IMPLEMENTATION)
0095
0096 template<class T>
0097 struct optional_swap_should_use_default_constructor : boost::false_type {} ;
0098
0099 #else
0100
0101 template<class T>
0102 struct optional_swap_should_use_default_constructor : has_nothrow_default_constructor<T> {} ;
0103
0104 #endif
0105
0106 template <class T>
0107 inline void swap ( optional<T>& x, optional<T>& y )
0108
0109 {
0110 optional_detail::swap_selector<optional_swap_should_use_default_constructor<T>::value>::optional_swap(x, y);
0111 }
0112
0113 }
0114
0115 #undef BOOST_OPTIONAL_DETAIL_MOVE
0116
0117 #endif