Chris@16
|
1 /*=============================================================================
|
Chris@16
|
2 Copyright (c) 2005-2012 Joel de Guzman
|
Chris@16
|
3 Copyright (c) 2005-2006 Dan Marsden
|
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(BOOST_FUSION_DEQUE_DETAIL_KEYED_ELEMENT_26112006_1330)
|
Chris@16
|
9 #define BOOST_FUSION_DEQUE_DETAIL_KEYED_ELEMENT_26112006_1330
|
Chris@16
|
10
|
Chris@101
|
11 #include <boost/fusion/support/config.hpp>
|
Chris@16
|
12 #include <boost/fusion/support/detail/access.hpp>
|
Chris@16
|
13 #include <boost/fusion/iterator/deref.hpp>
|
Chris@16
|
14 #include <boost/fusion/iterator/next.hpp>
|
Chris@16
|
15
|
Chris@16
|
16 namespace boost { namespace fusion
|
Chris@16
|
17 {
|
Chris@16
|
18 struct fusion_sequence_tag;
|
Chris@16
|
19 }}
|
Chris@16
|
20
|
Chris@16
|
21 namespace boost { namespace fusion { namespace detail
|
Chris@16
|
22 {
|
Chris@16
|
23 struct nil_keyed_element
|
Chris@16
|
24 {
|
Chris@16
|
25 typedef fusion_sequence_tag tag;
|
Chris@101
|
26 BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
27 void get();
|
Chris@16
|
28
|
Chris@16
|
29 template<typename It>
|
Chris@101
|
30 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
31 static nil_keyed_element
|
Chris@16
|
32 from_iterator(It const&)
|
Chris@16
|
33 {
|
Chris@16
|
34 return nil_keyed_element();
|
Chris@16
|
35 }
|
Chris@16
|
36 };
|
Chris@16
|
37
|
Chris@16
|
38 template <typename Key, typename Value, typename Rest>
|
Chris@16
|
39 struct keyed_element : Rest
|
Chris@16
|
40 {
|
Chris@16
|
41 typedef Rest base;
|
Chris@16
|
42 typedef fusion_sequence_tag tag;
|
Chris@16
|
43 using Rest::get;
|
Chris@16
|
44
|
Chris@16
|
45 template <typename It>
|
Chris@101
|
46 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
47 static keyed_element
|
Chris@16
|
48 from_iterator(It const& it)
|
Chris@16
|
49 {
|
Chris@16
|
50 return keyed_element(
|
Chris@16
|
51 *it, base::from_iterator(fusion::next(it)));
|
Chris@16
|
52 }
|
Chris@16
|
53
|
Chris@101
|
54 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
55 keyed_element(keyed_element const& rhs)
|
Chris@16
|
56 : Rest(rhs.get_base()), value_(rhs.value_)
|
Chris@16
|
57 {}
|
Chris@16
|
58
|
Chris@16
|
59 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@101
|
60 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
61 keyed_element(keyed_element&& rhs)
|
Chris@101
|
62 : Rest(BOOST_FUSION_FWD_ELEM(Rest, rhs.forward_base()))
|
Chris@101
|
63 , value_(BOOST_FUSION_FWD_ELEM(Value, rhs.value_))
|
Chris@16
|
64 {}
|
Chris@16
|
65 #endif
|
Chris@16
|
66
|
Chris@16
|
67 template <typename U, typename Rst>
|
Chris@101
|
68 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@101
|
69 keyed_element(keyed_element<Key, U, Rst> const& rhs
|
Chris@101
|
70 , typename enable_if<is_convertible<U, Value> >::type* = 0)
|
Chris@16
|
71 : Rest(rhs.get_base()), value_(rhs.value_)
|
Chris@16
|
72 {}
|
Chris@16
|
73
|
Chris@16
|
74 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@16
|
75 #endif
|
Chris@16
|
76
|
Chris@101
|
77 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@101
|
78 Rest& get_base() BOOST_NOEXCEPT
|
Chris@16
|
79 {
|
Chris@16
|
80 return *this;
|
Chris@16
|
81 }
|
Chris@16
|
82
|
Chris@101
|
83 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@101
|
84 Rest const& get_base() const BOOST_NOEXCEPT
|
Chris@16
|
85 {
|
Chris@16
|
86 return *this;
|
Chris@16
|
87 }
|
Chris@16
|
88
|
Chris@16
|
89 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@101
|
90 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@101
|
91 Rest&& forward_base() BOOST_NOEXCEPT
|
Chris@16
|
92 {
|
Chris@101
|
93 return BOOST_FUSION_FWD_ELEM(Rest, *static_cast<Rest*>(this));
|
Chris@16
|
94 }
|
Chris@16
|
95 #endif
|
Chris@16
|
96
|
Chris@101
|
97 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
98 typename cref_result<Value>::type get(Key) const
|
Chris@16
|
99 {
|
Chris@16
|
100 return value_;
|
Chris@16
|
101 }
|
Chris@16
|
102
|
Chris@101
|
103 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
104 typename ref_result<Value>::type get(Key)
|
Chris@16
|
105 {
|
Chris@16
|
106 return value_;
|
Chris@16
|
107 }
|
Chris@16
|
108
|
Chris@101
|
109 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
110 keyed_element(
|
Chris@16
|
111 typename detail::call_param<Value>::type value
|
Chris@16
|
112 , Rest const& rest)
|
Chris@16
|
113 : Rest(rest), value_(value)
|
Chris@16
|
114 {}
|
Chris@16
|
115
|
Chris@16
|
116 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@101
|
117 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
118 keyed_element(Value&& value, Rest&& rest)
|
Chris@101
|
119 : Rest(BOOST_FUSION_FWD_ELEM(Rest, rest))
|
Chris@101
|
120 , value_(BOOST_FUSION_FWD_ELEM(Value, value))
|
Chris@16
|
121 {}
|
Chris@16
|
122 #endif
|
Chris@16
|
123
|
Chris@101
|
124 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
125 keyed_element()
|
Chris@16
|
126 : Rest(), value_()
|
Chris@16
|
127 {}
|
Chris@16
|
128
|
Chris@16
|
129 template<typename U, typename Rst>
|
Chris@101
|
130 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
131 keyed_element& operator=(keyed_element<Key, U, Rst> const& rhs)
|
Chris@16
|
132 {
|
Chris@16
|
133 base::operator=(static_cast<Rst const&>(rhs)); // cast for msvc-7.1
|
Chris@16
|
134 value_ = rhs.value_;
|
Chris@16
|
135 return *this;
|
Chris@16
|
136 }
|
Chris@16
|
137
|
Chris@101
|
138 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
139 keyed_element& operator=(keyed_element const& rhs)
|
Chris@16
|
140 {
|
Chris@16
|
141 base::operator=(rhs);
|
Chris@16
|
142 value_ = rhs.value_;
|
Chris@16
|
143 return *this;
|
Chris@16
|
144 }
|
Chris@16
|
145
|
Chris@16
|
146 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@101
|
147 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
148 keyed_element& operator=(keyed_element&& rhs)
|
Chris@16
|
149 {
|
Chris@16
|
150 base::operator=(std::forward<keyed_element>(rhs));
|
Chris@101
|
151 value_ = BOOST_FUSION_FWD_ELEM(Value, rhs.value_);
|
Chris@16
|
152 return *this;
|
Chris@16
|
153 }
|
Chris@16
|
154 #endif
|
Chris@16
|
155
|
Chris@16
|
156 Value value_;
|
Chris@16
|
157 };
|
Chris@16
|
158
|
Chris@16
|
159 template<typename Elem, typename Key>
|
Chris@16
|
160 struct keyed_element_value_at
|
Chris@16
|
161 : keyed_element_value_at<typename Elem::base, Key>
|
Chris@16
|
162 {};
|
Chris@16
|
163
|
Chris@16
|
164 template<typename Key, typename Value, typename Rest>
|
Chris@16
|
165 struct keyed_element_value_at<keyed_element<Key, Value, Rest>, Key>
|
Chris@16
|
166 {
|
Chris@16
|
167 typedef Value type;
|
Chris@16
|
168 };
|
Chris@16
|
169 }}}
|
Chris@16
|
170
|
Chris@16
|
171 #endif
|