Chris@16: ////////////////////////////////////////////////////////////////////////////// Chris@16: // Chris@101: // (C) Copyright Ion Gaztanaga 2005-2013. Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. Chris@16: // (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: // See http://www.boost.org/libs/container for documentation. Chris@16: // Chris@16: ////////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: #ifndef BOOST_CONTAINER_CONTAINER_DETAIL_PAIR_HPP Chris@16: #define BOOST_CONTAINER_CONTAINER_DETAIL_PAIR_HPP Chris@16: Chris@101: #ifndef BOOST_CONFIG_HPP Chris@101: # include Chris@101: #endif Chris@101: Chris@101: #if defined(BOOST_HAS_PRAGMA_ONCE) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@101: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@101: #include //swap Chris@16: Chris@101: #include //pair Chris@101: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace container { Chris@16: namespace container_detail { Chris@16: Chris@16: template Chris@16: struct pair; Chris@16: Chris@16: template Chris@16: struct is_pair Chris@16: { Chris@16: static const bool value = false; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct is_pair< pair > Chris@16: { Chris@16: static const bool value = true; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct is_pair< std::pair > Chris@16: { Chris@16: static const bool value = true; Chris@16: }; Chris@16: Chris@16: struct pair_nat; Chris@16: Chris@16: struct piecewise_construct_t { }; Chris@16: static const piecewise_construct_t piecewise_construct = piecewise_construct_t(); Chris@16: Chris@16: /* Chris@16: template Chris@16: struct pair Chris@16: { Chris@16: template pair(pair&& p); Chris@16: template Chris@16: pair(piecewise_construct_t, tuple first_args, Chris@16: tuple second_args); Chris@16: Chris@16: template pair& operator=(const pair& p); Chris@16: pair& operator=(pair&& p) noexcept(is_nothrow_move_assignable::value && Chris@16: is_nothrow_move_assignable::value); Chris@16: template pair& operator=(pair&& p); Chris@16: Chris@16: void swap(pair& p) noexcept(noexcept(swap(first, p.first)) && Chris@16: noexcept(swap(second, p.second))); Chris@16: }; Chris@16: Chris@16: template bool operator==(const pair&, const pair&); Chris@16: template bool operator!=(const pair&, const pair&); Chris@16: template bool operator< (const pair&, const pair&); Chris@16: template bool operator> (const pair&, const pair&); Chris@16: template bool operator>=(const pair&, const pair&); Chris@16: template bool operator<=(const pair&, const pair&); Chris@16: */ Chris@16: Chris@16: Chris@16: template Chris@16: struct pair Chris@16: { Chris@16: private: Chris@16: BOOST_COPYABLE_AND_MOVABLE(pair) Chris@16: Chris@16: public: Chris@16: typedef T1 first_type; Chris@16: typedef T2 second_type; Chris@16: Chris@16: T1 first; Chris@16: T2 second; Chris@16: Chris@16: //Default constructor Chris@16: pair() Chris@16: : first(), second() Chris@16: {} Chris@16: Chris@16: //pair copy assignment Chris@16: pair(const pair& x) Chris@16: : first(x.first), second(x.second) Chris@16: {} Chris@16: Chris@16: //pair move constructor Chris@16: pair(BOOST_RV_REF(pair) p) Chris@16: : first(::boost::move(p.first)), second(::boost::move(p.second)) Chris@16: {} Chris@16: Chris@16: template Chris@16: pair(const pair &p) Chris@16: : first(p.first), second(p.second) Chris@16: {} Chris@16: Chris@16: template Chris@16: pair(BOOST_RV_REF_BEG pair BOOST_RV_REF_END p) Chris@16: : first(::boost::move(p.first)), second(::boost::move(p.second)) Chris@16: {} Chris@16: Chris@16: //pair from two values Chris@16: pair(const T1 &t1, const T2 &t2) Chris@16: : first(t1) Chris@16: , second(t2) Chris@16: {} Chris@16: Chris@16: template Chris@16: pair(BOOST_FWD_REF(U) u, BOOST_FWD_REF(V) v) Chris@16: : first(::boost::forward(u)) Chris@16: , second(::boost::forward(v)) Chris@16: {} Chris@16: Chris@16: //And now compatibility with std::pair Chris@16: pair(const std::pair& x) Chris@16: : first(x.first), second(x.second) Chris@16: {} Chris@16: Chris@16: template Chris@16: pair(const std::pair& p) Chris@16: : first(p.first), second(p.second) Chris@16: {} Chris@16: Chris@16: pair(BOOST_RV_REF_BEG std::pair BOOST_RV_REF_END p) Chris@16: : first(::boost::move(p.first)), second(::boost::move(p.second)) Chris@16: {} Chris@16: Chris@16: template Chris@16: pair(BOOST_RV_REF_BEG std::pair BOOST_RV_REF_END p) Chris@16: : first(::boost::move(p.first)), second(::boost::move(p.second)) Chris@16: {} Chris@16: Chris@16: //piecewise_construct missing Chris@16: //template pair(pair&& p); Chris@16: //template Chris@16: // pair(piecewise_construct_t, tuple first_args, Chris@16: // tuple second_args); Chris@16: Chris@16: //pair copy assignment Chris@16: pair& operator=(BOOST_COPY_ASSIGN_REF(pair) p) Chris@16: { Chris@16: first = p.first; Chris@16: second = p.second; Chris@16: return *this; Chris@16: } Chris@16: Chris@16: //pair move assignment Chris@16: pair& operator=(BOOST_RV_REF(pair) p) Chris@16: { Chris@16: first = ::boost::move(p.first); Chris@16: second = ::boost::move(p.second); Chris@16: return *this; Chris@16: } Chris@16: Chris@16: template Chris@16: typename ::boost::container::container_detail::enable_if_c Chris@16: < !(::boost::container::container_detail::is_same::value && Chris@16: ::boost::container::container_detail::is_same::value) Chris@16: , pair &>::type Chris@16: operator=(const pair&p) Chris@16: { Chris@16: first = p.first; Chris@16: second = p.second; Chris@16: return *this; Chris@16: } Chris@16: Chris@16: template Chris@16: typename ::boost::container::container_detail::enable_if_c Chris@16: < !(::boost::container::container_detail::is_same::value && Chris@16: ::boost::container::container_detail::is_same::value) Chris@16: , pair &>::type Chris@16: operator=(BOOST_RV_REF_BEG pair BOOST_RV_REF_END p) Chris@16: { Chris@16: first = ::boost::move(p.first); Chris@16: second = ::boost::move(p.second); Chris@16: return *this; Chris@16: } Chris@16: Chris@16: //std::pair copy assignment Chris@16: pair& operator=(const std::pair &p) Chris@16: { Chris@16: first = p.first; Chris@16: second = p.second; Chris@16: return *this; Chris@16: } Chris@16: Chris@16: template Chris@16: pair& operator=(const std::pair &p) Chris@16: { Chris@16: first = ::boost::move(p.first); Chris@16: second = ::boost::move(p.second); Chris@16: return *this; Chris@16: } Chris@16: Chris@16: //std::pair move assignment Chris@16: pair& operator=(BOOST_RV_REF_BEG std::pair BOOST_RV_REF_END p) Chris@16: { Chris@16: first = ::boost::move(p.first); Chris@16: second = ::boost::move(p.second); Chris@16: return *this; Chris@16: } Chris@16: Chris@16: template Chris@16: pair& operator=(BOOST_RV_REF_BEG std::pair BOOST_RV_REF_END p) Chris@16: { Chris@16: first = ::boost::move(p.first); Chris@16: second = ::boost::move(p.second); Chris@16: return *this; Chris@16: } Chris@16: Chris@16: //swap Chris@16: void swap(pair& p) Chris@16: { Chris@101: ::boost::adl_move_swap(this->first, p.first); Chris@101: ::boost::adl_move_swap(this->second, p.second); Chris@16: } Chris@16: }; Chris@16: Chris@16: template Chris@16: inline bool operator==(const pair& x, const pair& y) Chris@16: { return static_cast(x.first == y.first && x.second == y.second); } Chris@16: Chris@16: template Chris@16: inline bool operator< (const pair& x, const pair& y) Chris@16: { return static_cast(x.first < y.first || Chris@16: (!(y.first < x.first) && x.second < y.second)); } Chris@16: Chris@16: template Chris@16: inline bool operator!=(const pair& x, const pair& y) Chris@16: { return static_cast(!(x == y)); } Chris@16: Chris@16: template Chris@16: inline bool operator> (const pair& x, const pair& y) Chris@16: { return y < x; } Chris@16: Chris@16: template Chris@16: inline bool operator>=(const pair& x, const pair& y) Chris@16: { return static_cast(!(x < y)); } Chris@16: Chris@16: template Chris@16: inline bool operator<=(const pair& x, const pair& y) Chris@16: { return static_cast(!(y < x)); } Chris@16: Chris@16: template Chris@16: inline pair make_pair(T1 x, T2 y) Chris@16: { return pair(x, y); } Chris@16: Chris@16: template Chris@16: inline void swap(pair& x, pair& y) Chris@101: { x.swap(y); } Chris@16: Chris@16: } //namespace container_detail { Chris@16: } //namespace container { Chris@16: Chris@16: Chris@16: //Without this specialization recursive flat_(multi)map instantiation fails Chris@16: //because is_enum needs to instantiate the recursive pair, leading to a compilation error). Chris@16: //This breaks the cycle clearly stating that pair is not an enum avoiding any instantiation. Chris@16: template Chris@16: struct is_enum; Chris@16: Chris@16: template Chris@16: struct is_enum< ::boost::container::container_detail::pair > Chris@16: { Chris@16: static const bool value = false; Chris@16: }; Chris@16: Chris@101: template Chris@101: struct is_class; Chris@101: Chris@16: //This specialization is needed to avoid instantiation of pair in Chris@16: //is_class, and allow recursive maps. Chris@16: template Chris@16: struct is_class< ::boost::container::container_detail::pair > Chris@101: { Chris@101: static const bool value = true; Chris@101: }; Chris@16: Chris@16: #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES Chris@16: Chris@16: template Chris@16: struct has_move_emulation_enabled< ::boost::container::container_detail::pair > Chris@101: { Chris@101: static const bool value = true; Chris@101: }; Chris@16: Chris@16: #endif Chris@16: Chris@101: namespace move_detail{ Chris@101: Chris@101: template Chris@101: struct is_class_or_union; Chris@101: Chris@101: template Chris@101: struct is_class_or_union< ::boost::container::container_detail::pair > Chris@101: //This specialization is needed to avoid instantiation of pair in Chris@101: //is_class, and allow recursive maps. Chris@101: { Chris@101: static const bool value = true; Chris@101: }; Chris@101: Chris@101: Chris@101: } //namespace move_detail{ Chris@16: Chris@16: } //namespace boost { Chris@16: Chris@16: #include Chris@16: Chris@16: #endif //#ifndef BOOST_CONTAINER_DETAIL_PAIR_HPP