1 /*============================================================================= 2 Copyright (c) 2001-2011 Joel de Guzman 3 Copyright (c) 2006 Tobias Schwinger 4 5 Distributed under the Boost Software License, Version 1.0. (See accompanying 6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 ==============================================================================*/ 8 #if !defined(FUSION_PAIR_07222005_1203) 9 #define FUSION_PAIR_07222005_1203 10 11 #include <boost/fusion/support/config.hpp> 12 #include <iosfwd> 13 14 #include <boost/fusion/support/detail/access.hpp> 15 #include <boost/fusion/support/detail/as_fusion_element.hpp> 16 #include <boost/config.hpp> 17 #include <boost/utility/enable_if.hpp> 18 #include <boost/type_traits/is_convertible.hpp> 19 #include <boost/type_traits/is_lvalue_reference.hpp> 20 21 #if defined (BOOST_MSVC) 22 # pragma warning(push) 23 # pragma warning (disable: 4512) // assignment operator could not be generated. 24 #endif 25 26 namespace boost { namespace fusion 27 { 28 // A half runtime pair where the first type does not have data 29 template <typename First, typename Second> 30 struct pair 31 { 32 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED pairboost::fusion::pair33 pair() 34 : second() {} 35 36 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED pairboost::fusion::pair37 pair(pair const& rhs) 38 : second(rhs.second) {} 39 40 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 41 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED pairboost::fusion::pair42 pair(pair&& rhs) 43 : second(BOOST_FUSION_FWD_ELEM(Second, rhs.second)) {} 44 #endif 45 46 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED pairboost::fusion::pair47 pair(typename detail::call_param<Second>::type val) 48 : second(val) {} 49 50 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 51 template <typename Second2> 52 BOOST_FUSION_GPU_ENABLED pairboost::fusion::pair53 pair(Second2&& val 54 , typename boost::disable_if<is_lvalue_reference<Second2> >::type* /* dummy */ = 0 55 , typename boost::enable_if<is_convertible<Second2, Second> >::type* /*dummy*/ = 0 56 ) : second(BOOST_FUSION_FWD_ELEM(Second, val)) {} 57 #endif 58 59 template <typename Second2> 60 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED pairboost::fusion::pair61 pair(pair<First, Second2> const& rhs) 62 : second(rhs.second) {} 63 64 template <typename Second2> 65 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED operator =boost::fusion::pair66 pair& operator=(pair<First, Second2> const& rhs) 67 { 68 second = rhs.second; 69 return *this; 70 } 71 72 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED operator =boost::fusion::pair73 pair& operator=(pair const& rhs) 74 { 75 second = rhs.second; 76 return *this; 77 } 78 79 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 80 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED operator =boost::fusion::pair81 pair& operator=(pair&& rhs) 82 { 83 second = BOOST_FUSION_FWD_ELEM(Second, rhs.second); 84 return *this; 85 } 86 #endif 87 88 typedef First first_type; 89 typedef Second second_type; 90 Second second; 91 }; 92 93 namespace result_of 94 { 95 template<typename First, typename Second> 96 struct make_pair 97 { 98 typedef fusion::pair<First, 99 typename detail::as_fusion_element<Second>::type> type; 100 }; 101 102 template<class Pair> 103 struct first 104 { 105 typedef typename Pair::first_type type; 106 }; 107 108 template<class Pair> 109 struct second 110 { 111 typedef typename Pair::second_type type; 112 }; 113 } 114 115 template <typename First, typename Second> 116 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED 117 inline typename result_of::make_pair<First,Second>::type make_pair(Second const & val)118 make_pair(Second const& val) 119 { 120 return pair<First, typename detail::as_fusion_element<Second>::type>(val); 121 } 122 123 template <typename First, typename Second> 124 inline std::ostream& operator <<(std::ostream & os,pair<First,Second> const & p)125 operator<<(std::ostream& os, pair<First, Second> const& p) 126 { 127 os << p.second; 128 return os; 129 } 130 131 template <typename First, typename Second> 132 inline std::istream& operator >>(std::istream & is,pair<First,Second> & p)133 operator>>(std::istream& is, pair<First, Second>& p) 134 { 135 is >> p.second; 136 return is; 137 } 138 139 template <typename First, typename SecondL, typename SecondR> 140 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED 141 inline bool operator ==(pair<First,SecondL> const & l,pair<First,SecondR> const & r)142 operator==(pair<First, SecondL> const& l, pair<First, SecondR> const& r) 143 { 144 return l.second == r.second; 145 } 146 147 template <typename First, typename SecondL, typename SecondR> 148 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED 149 inline bool operator !=(pair<First,SecondL> const & l,pair<First,SecondR> const & r)150 operator!=(pair<First, SecondL> const& l, pair<First, SecondR> const& r) 151 { 152 return l.second != r.second; 153 } 154 155 template <typename First, typename SecondL, typename SecondR> 156 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED 157 inline bool operator <(pair<First,SecondL> const & l,pair<First,SecondR> const & r)158 operator<(pair<First, SecondL> const& l, pair<First, SecondR> const& r) 159 { 160 return l.second < r.second; 161 } 162 }} 163 164 #if defined (BOOST_MSVC) 165 # pragma warning(pop) 166 #endif 167 168 #endif 169