////////////////////////////////////////////////////////////////////////////// // // (C) Copyright Ion Gaztanaga 2005-2009. // // 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_CONTAINERS_CONTAINERS_DETAIL_PAIR_HPP #define BOOST_CONTAINERS_CONTAINERS_DETAIL_PAIR_HPP #if (defined _MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif #include #include #include #include #include //std::pair #include #ifndef BOOST_CONTAINERS_PERFECT_FORWARDING #include #endif namespace boost { namespace container { namespace containers_detail { template struct pair { private: BOOST_COPYABLE_AND_MOVABLE(pair) public: typedef T1 first_type; typedef T2 second_type; T1 first; T2 second; //std::pair compatibility template pair(const std::pair& p) : first(p.first), second(p.second) {} //To resolve ambiguity with the variadic constructor of 1 argument //and the previous constructor pair(std::pair& x) : first(x.first), second(x.second) {} template pair(BOOST_INTERPROCESS_RV_REF_2_TEMPL_ARGS(std::pair, D, S) p) : first(boost::interprocess::move(p.first)), second(boost::interprocess::move(p.second)) {} pair() : first(), second() {} pair(const pair& x) : first(x.first), second(x.second) {} //To resolve ambiguity with the variadic constructor of 1 argument //and the copy constructor pair(pair& x) : first(x.first), second(x.second) {} pair(BOOST_INTERPROCESS_RV_REF(pair) p) : first(boost::interprocess::move(p.first)), second(boost::interprocess::move(p.second)) {} template pair(BOOST_INTERPROCESS_RV_REF_2_TEMPL_ARGS(pair, D, S) p) : first(boost::interprocess::move(p.first)), second(boost::interprocess::move(p.second)) {} #ifdef BOOST_CONTAINERS_PERFECT_FORWARDING template pair(U &&u, Args &&... args) : first(boost::interprocess::forward(u)) , second(boost::interprocess::forward(args)...) {} #else template pair( BOOST_CONTAINERS_PARAM(U, u) #ifndef BOOST_HAS_RVALUE_REFS , typename containers_detail::disable_if < containers_detail::is_same > >::type* = 0 #endif ) : first(boost::interprocess::forward(const_cast(u))) {} #define BOOST_PP_LOCAL_MACRO(n) \ template \ pair(BOOST_CONTAINERS_PARAM(U, u) \ ,BOOST_PP_ENUM(n, BOOST_CONTAINERS_PP_PARAM_LIST, _)) \ : first(boost::interprocess::forward(const_cast(u))) \ , second(BOOST_PP_ENUM(n, BOOST_CONTAINERS_PP_PARAM_FORWARD, _)) \ {} \ //! #define BOOST_PP_LOCAL_LIMITS (1, BOOST_CONTAINERS_MAX_CONSTRUCTOR_PARAMETERS) #include BOOST_PP_LOCAL_ITERATE() #endif pair& operator=(BOOST_INTERPROCESS_COPY_ASSIGN_REF(pair) p) { first = p.first; second = p.second; return *this; } pair& operator=(BOOST_INTERPROCESS_RV_REF(pair) p) { first = boost::interprocess::move(p.first); second = boost::interprocess::move(p.second); return *this; } pair& operator=(BOOST_INTERPROCESS_RV_REF_2_TEMPL_ARGS(std::pair, T1, T2) p) { first = boost::interprocess::move(p.first); second = boost::interprocess::move(p.second); return *this; } template pair& operator=(BOOST_INTERPROCESS_RV_REF_2_TEMPL_ARGS(std::pair, D, S) p) { first = boost::interprocess::move(p.first); second = boost::interprocess::move(p.second); return *this; } void swap(pair& p) { std::swap(*this, p); } }; 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) { swap(x.first, y.first); swap(x.second, y.second); } } //namespace containers_detail { } //namespace container { } //namespace boost { #include #endif //#ifndef BOOST_CONTAINERS_DETAIL_PAIR_HPP