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