////////////////////////////////////////////////////////////////////////////// // // (C) Copyright Ion Gaztanaga 2005-2013. // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org/libs/container for documentation. // ////////////////////////////////////////////////////////////////////////////// #ifndef BOOST_CONTAINER_CONTAINER_DETAIL_PAIR_HPP #define BOOST_CONTAINER_CONTAINER_DETAIL_PAIR_HPP #ifndef BOOST_CONFIG_HPP # include #endif #if defined(BOOST_HAS_PRAGMA_ONCE) # pragma once #endif #include #include #include #include #include #include #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) # include #endif #include //swap #include //pair #include #include namespace boost { namespace tuples { struct null_type; template < class T0, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9> class tuple; } //namespace tuples { } //namespace boost { namespace boost { namespace container { namespace pair_impl { template struct is_boost_tuple { static const bool value = false; }; template < class T0, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9> struct is_boost_tuple< boost::tuples::tuple > { static const bool value = true; }; template struct disable_if_boost_tuple : boost::container::container_detail::disable_if< is_boost_tuple > {}; template struct is_tuple_null { static const bool value = false; }; template<> struct is_tuple_null { static const bool value = true; }; }}} #if defined(BOOST_MSVC) && (_CPPLIB_VER == 520) //MSVC 2010 tuple marker namespace std { namespace tr1 { struct _Nil; }} #elif defined(BOOST_MSVC) && (_CPPLIB_VER == 540) //MSVC 2012 tuple marker namespace std { struct _Nil; } #endif namespace boost { namespace container { #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED template struct std_piecewise_construct_holder { static ::std::piecewise_construct_t *dummy; }; template ::std::piecewise_construct_t *std_piecewise_construct_holder::dummy = reinterpret_cast< ::std::piecewise_construct_t *>(0x01234); //Avoid sanitizer errors on references to null pointers typedef const std::piecewise_construct_t & piecewise_construct_t; struct try_emplace_t{}; #else //! The piecewise_construct_t struct is an empty structure type used as a unique type to //! disambiguate used to disambiguate between different functions that take two tuple arguments. typedef unspecified piecewise_construct_t; #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED //! A instance of type //! piecewise_construct_t static piecewise_construct_t piecewise_construct = BOOST_CONTAINER_DOC1ST(unspecified, *std_piecewise_construct_holder<>::dummy); ///@cond namespace container_detail { struct piecewise_construct_use { //Avoid warnings of unused "piecewise_construct" piecewise_construct_use() { (void)&::boost::container::piecewise_construct; } }; template struct pair; template struct is_pair { static const bool value = false; }; template struct is_pair< pair > { static const bool value = true; }; template struct is_pair< std::pair > { static const bool value = true; }; template struct is_not_pair { static const bool value = !is_pair::value; }; template struct is_std_pair { static const bool value = false; }; template struct is_std_pair< std::pair > { static const bool value = true; }; struct pair_nat; template void get(T); //to enable ADL ///@endcond template struct pair { private: BOOST_COPYABLE_AND_MOVABLE(pair) public: typedef T1 first_type; typedef T2 second_type; T1 first; T2 second; //Default constructor pair() : first(), second() {} //pair copy assignment pair(const pair& x) : first(x.first), second(x.second) {} //pair move constructor pair(BOOST_RV_REF(pair) p) : first(::boost::move(p.first)), second(::boost::move(p.second)) {} template pair(const pair &p) : first(p.first), second(p.second) {} template pair(BOOST_RV_REF_BEG pair BOOST_RV_REF_END p) : first(::boost::move(p.first)), second(::boost::move(p.second)) {} //pair from two values pair(const T1 &t1, const T2 &t2) : first(t1) , second(t2) {} template pair(BOOST_FWD_REF(U) u, BOOST_FWD_REF(V) v) : first(::boost::forward(u)) , second(::boost::forward(v)) {} //And now compatibility with std::pair pair(const std::pair& x) : first(x.first), second(x.second) {} template pair(const std::pair& p) : first(p.first), second(p.second) {} pair(BOOST_RV_REF_BEG std::pair BOOST_RV_REF_END p) : first(::boost::move(p.first)), second(::boost::move(p.second)) {} template pair(BOOST_RV_REF_BEG std::pair BOOST_RV_REF_END p) : first(::boost::move(p.first)), second(::boost::move(p.second)) {} #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) template< class KeyType, class ...Args> pair(try_emplace_t, BOOST_FWD_REF(KeyType) k, Args && ...args) : first(boost::forward(k)), second(::boost::forward(args)...)\ {} #else //piecewise construction from boost::tuple #define BOOST_PAIR_TRY_EMPLACE_CONSTRUCT_CODE(N)\ template< class KeyType BOOST_MOVE_I##N BOOST_MOVE_CLASS##N > \ pair( try_emplace_t, BOOST_FWD_REF(KeyType) k BOOST_MOVE_I##N BOOST_MOVE_UREF##N )\ : first(boost::forward(k)), second(BOOST_MOVE_FWD##N)\ {}\ // BOOST_MOVE_ITERATE_0TO9(BOOST_PAIR_TRY_EMPLACE_CONSTRUCT_CODE) #undef BOOST_PAIR_TRY_EMPLACE_CONSTRUCT_CODE #endif //BOOST_NO_CXX11_VARIADIC_TEMPLATES //piecewise construction from boost::tuple #define BOOST_PAIR_PIECEWISE_CONSTRUCT_BOOST_TUPLE_CODE(N,M)\ template< template class BoostTuple \ BOOST_MOVE_I_IF(BOOST_MOVE_OR(N,M)) BOOST_MOVE_CLASS##N BOOST_MOVE_I_IF(BOOST_MOVE_AND(N,M)) BOOST_MOVE_CLASSQ##M > \ pair( piecewise_construct_t\ , BoostTuple p\ , BoostTuple q\ , typename container_detail::enable_if_c\ < pair_impl::is_boost_tuple< BoostTuple >::value &&\ !(pair_impl::is_tuple_null::value || pair_impl::is_tuple_null::value) \ >::type* = 0\ )\ : first(BOOST_MOVE_TMPL_GET##N), second(BOOST_MOVE_TMPL_GETQ##M)\ { (void)p; (void)q; }\ // BOOST_MOVE_ITER2D_0TOMAX(9, BOOST_PAIR_PIECEWISE_CONSTRUCT_BOOST_TUPLE_CODE) #undef BOOST_PAIR_PIECEWISE_CONSTRUCT_BOOST_TUPLE_CODE //piecewise construction from variadic tuple (with delegating constructors) #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) # if !defined(BOOST_CONTAINER_NO_CXX11_DELEGATING_CONSTRUCTORS) private: template class Tuple, class... Args1, class... Args2, size_t... Indexes1, size_t... Indexes2> pair(Tuple& t1, Tuple& t2, index_tuple, index_tuple) : first (::boost::forward(get(t1))...) , second(::boost::forward(get(t2))...) { (void) t1; (void)t2; } public: template< template class Tuple, class... Args1, class... Args2 , class = typename pair_impl::disable_if_boost_tuple< Tuple >::type> pair(piecewise_construct_t, Tuple t1, Tuple t2) : pair(t1, t2, typename build_number_seq::type(), typename build_number_seq::type()) {} # else //piecewise construction from variadic tuple (suboptimal, without delegating constructors) private: template class Tuple, typename... Args> static T build_from_args(Tuple&& t) { return do_build_from_args(::boost::move(t), typename build_number_seq::type()); } template class Tuple, typename... Args, std::size_t... Indexes> static T do_build_from_args(Tuple && t, const index_tuple&) { (void)t; return T(::boost::forward(get(t))...); } public: template< template class Tuple, class... Args1, class... Args2 , class = typename pair_impl::disable_if_boost_tuple< Tuple >::type> pair(piecewise_construct_t, Tuple t1, Tuple t2) : first (build_from_args (::boost::move(t1))) , second (build_from_args(::boost::move(t2))) {} # endif //BOOST_NO_CXX11_VARIADIC_TEMPLATES #elif defined(BOOST_MSVC) && (_CPPLIB_VER == 520) //MSVC 2010 tuple implementation #define BOOST_PAIR_PIECEWISE_CONSTRUCT_MSVC2010_TUPLE_CODE(N,M)\ template< template class StdTuple \ BOOST_MOVE_I_IF(BOOST_MOVE_OR(N,M)) BOOST_MOVE_CLASS##N BOOST_MOVE_I_IF(BOOST_MOVE_AND(N,M)) BOOST_MOVE_CLASSQ##M > \ pair( piecewise_construct_t\ , StdTuple p\ , StdTuple q)\ : first(BOOST_MOVE_GET_IDX##N), second(BOOST_MOVE_GET_IDXQ##M)\ { (void)p; (void)q; }\ // BOOST_MOVE_ITER2D_0TOMAX(9, BOOST_PAIR_PIECEWISE_CONSTRUCT_MSVC2010_TUPLE_CODE) #undef BOOST_PAIR_PIECEWISE_CONSTRUCT_MSVC2010_TUPLE_CODE #elif defined(BOOST_MSVC) && (_CPPLIB_VER == 540) #if _VARIADIC_MAX >= 9 #define BOOST_PAIR_PIECEWISE_CONSTRUCT_MSVC2012_TUPLE_MAX_IT 9 #else #define BOOST_PAIR_PIECEWISE_CONSTRUCT_MSVC2012_TUPLE_MAX_IT BOOST_MOVE_ADD(_VARIADIC_MAX, 1) #endif //MSVC 2012 tuple implementation #define BOOST_PAIR_PIECEWISE_CONSTRUCT_MSVC2012_TUPLE_CODE(N,M)\ template< template class StdTuple \ BOOST_MOVE_I_IF(BOOST_MOVE_OR(N,M)) BOOST_MOVE_CLASS##N BOOST_MOVE_I_IF(BOOST_MOVE_AND(N,M)) BOOST_MOVE_CLASSQ##M > \ pair( piecewise_construct_t\ , StdTuple p\ , StdTuple q)\ : first(BOOST_MOVE_GET_IDX##N), second(BOOST_MOVE_GET_IDXQ##M)\ { (void)p; (void)q; }\ // BOOST_MOVE_ITER2D_0TOMAX(BOOST_PAIR_PIECEWISE_CONSTRUCT_MSVC2012_TUPLE_MAX_IT, BOOST_PAIR_PIECEWISE_CONSTRUCT_MSVC2012_TUPLE_CODE) #undef BOOST_PAIR_PIECEWISE_CONSTRUCT_MSVC2010_TUPLE_CODE #undef BOOST_PAIR_PIECEWISE_CONSTRUCT_MSVC2012_TUPLE_MAX_IT #endif //pair copy assignment pair& operator=(BOOST_COPY_ASSIGN_REF(pair) p) { first = p.first; second = p.second; return *this; } //pair move assignment pair& operator=(BOOST_RV_REF(pair) p) { first = ::boost::move(p.first); second = ::boost::move(p.second); return *this; } template typename ::boost::container::container_detail::disable_if_or < pair & , ::boost::container::container_detail::is_same , ::boost::container::container_detail::is_same >::type operator=(const pair&p) { first = p.first; second = p.second; return *this; } template typename ::boost::container::container_detail::disable_if_or < pair & , ::boost::container::container_detail::is_same , ::boost::container::container_detail::is_same >::type operator=(BOOST_RV_REF_BEG pair BOOST_RV_REF_END p) { first = ::boost::move(p.first); second = ::boost::move(p.second); return *this; } //std::pair copy assignment pair& operator=(const std::pair &p) { first = p.first; second = p.second; return *this; } template pair& operator=(const std::pair &p) { first = ::boost::move(p.first); second = ::boost::move(p.second); return *this; } //std::pair move assignment pair& operator=(BOOST_RV_REF_BEG std::pair BOOST_RV_REF_END p) { first = ::boost::move(p.first); second = ::boost::move(p.second); return *this; } template pair& operator=(BOOST_RV_REF_BEG std::pair BOOST_RV_REF_END p) { first = ::boost::move(p.first); second = ::boost::move(p.second); return *this; } //swap void swap(pair& p) { ::boost::adl_move_swap(this->first, p.first); ::boost::adl_move_swap(this->second, p.second); } }; template inline bool operator==(const pair& x, const pair& y) { return static_cast(x.first == y.first && x.second == y.second); } template inline bool operator< (const pair& x, const pair& y) { return static_cast(x.first < y.first || (!(y.first < x.first) && x.second < y.second)); } template inline bool operator!=(const pair& x, const pair& y) { return static_cast(!(x == y)); } template inline bool operator> (const pair& x, const pair& y) { return y < x; } template inline bool operator>=(const pair& x, const pair& y) { return static_cast(!(x < y)); } template inline bool operator<=(const pair& x, const pair& y) { return static_cast(!(y < x)); } template inline pair make_pair(T1 x, T2 y) { return pair(x, y); } template inline void swap(pair& x, pair& y) { x.swap(y); } } //namespace container_detail { } //namespace container { #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES template struct has_move_emulation_enabled< ::boost::container::container_detail::pair > { static const bool value = true; }; #endif namespace move_detail{ template struct is_class_or_union; template struct is_class_or_union< ::boost::container::container_detail::pair > //This specialization is needed to avoid instantiation of pair in //is_class, and allow recursive maps. { static const bool value = true; }; template struct is_class_or_union< std::pair > //This specialization is needed to avoid instantiation of pair in //is_class, and allow recursive maps. { static const bool value = true; }; template struct is_union; template struct is_union< ::boost::container::container_detail::pair > //This specialization is needed to avoid instantiation of pair in //is_class, and allow recursive maps. { static const bool value = false; }; template struct is_union< std::pair > //This specialization is needed to avoid instantiation of pair in //is_class, and allow recursive maps. { static const bool value = false; }; template struct is_class; template struct is_class< ::boost::container::container_detail::pair > //This specialization is needed to avoid instantiation of pair in //is_class, and allow recursive maps. { static const bool value = true; }; template struct is_class< std::pair > //This specialization is needed to avoid instantiation of pair in //is_class, and allow recursive maps. { static const bool value = true; }; } //namespace move_detail{ } //namespace boost { #include #endif //#ifndef BOOST_CONTAINER_DETAIL_PAIR_HPP