Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/range/adaptor/map.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children | c530137014c0 |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
1 // Boost.Range library | |
2 // | |
3 // Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. Use, modification and | |
4 // distribution is subject to the Boost Software License, Version | |
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
6 // http://www.boost.org/LICENSE_1_0.txt) | |
7 // | |
8 // For more information, see http://www.boost.org/libs/range/ | |
9 // | |
10 | |
11 #ifndef BOOST_RANGE_ADAPTOR_MAP_HPP | |
12 #define BOOST_RANGE_ADAPTOR_MAP_HPP | |
13 | |
14 #include <boost/range/adaptor/transformed.hpp> | |
15 #include <boost/range/iterator_range.hpp> | |
16 #include <boost/range/value_type.hpp> | |
17 #include <boost/range/reference.hpp> | |
18 | |
19 namespace boost | |
20 { | |
21 namespace range_detail | |
22 { | |
23 struct map_keys_forwarder {}; | |
24 struct map_values_forwarder {}; | |
25 | |
26 template< class Map > | |
27 struct select_first | |
28 { | |
29 typedef BOOST_DEDUCED_TYPENAME range_reference<const Map>::type argument_type; | |
30 typedef const BOOST_DEDUCED_TYPENAME range_value<const Map>::type::first_type& result_type; | |
31 | |
32 result_type operator()( argument_type r ) const | |
33 { | |
34 return r.first; | |
35 } | |
36 }; | |
37 | |
38 template< class Map > | |
39 struct select_second_mutable | |
40 { | |
41 typedef BOOST_DEDUCED_TYPENAME range_reference<Map>::type argument_type; | |
42 typedef BOOST_DEDUCED_TYPENAME range_value<Map>::type::second_type& result_type; | |
43 | |
44 result_type operator()( argument_type r ) const | |
45 { | |
46 return r.second; | |
47 } | |
48 }; | |
49 | |
50 template< class Map > | |
51 struct select_second_const | |
52 { | |
53 typedef BOOST_DEDUCED_TYPENAME range_reference<const Map>::type argument_type; | |
54 typedef const BOOST_DEDUCED_TYPENAME range_value<const Map>::type::second_type& result_type; | |
55 | |
56 result_type operator()( argument_type r ) const | |
57 { | |
58 return r.second; | |
59 } | |
60 }; | |
61 | |
62 template<class StdPairRng> | |
63 class select_first_range | |
64 : public transformed_range< | |
65 select_first<StdPairRng>, | |
66 const StdPairRng> | |
67 { | |
68 typedef transformed_range<select_first<StdPairRng>, const StdPairRng> base; | |
69 public: | |
70 typedef select_first<StdPairRng> transform_fn_type; | |
71 typedef const StdPairRng source_range_type; | |
72 | |
73 select_first_range(transform_fn_type fn, source_range_type& rng) | |
74 : base(fn, rng) | |
75 { | |
76 } | |
77 | |
78 select_first_range(const base& other) : base(other) {} | |
79 }; | |
80 | |
81 template<class StdPairRng> | |
82 class select_second_mutable_range | |
83 : public transformed_range< | |
84 select_second_mutable<StdPairRng>, | |
85 StdPairRng> | |
86 { | |
87 typedef transformed_range<select_second_mutable<StdPairRng>, StdPairRng> base; | |
88 public: | |
89 typedef select_second_mutable<StdPairRng> transform_fn_type; | |
90 typedef StdPairRng source_range_type; | |
91 | |
92 select_second_mutable_range(transform_fn_type fn, source_range_type& rng) | |
93 : base(fn, rng) | |
94 { | |
95 } | |
96 | |
97 select_second_mutable_range(const base& other) : base(other) {} | |
98 }; | |
99 | |
100 template<class StdPairRng> | |
101 class select_second_const_range | |
102 : public transformed_range< | |
103 select_second_const<StdPairRng>, | |
104 const StdPairRng> | |
105 { | |
106 typedef transformed_range<select_second_const<StdPairRng>, const StdPairRng> base; | |
107 public: | |
108 typedef select_second_const<StdPairRng> transform_fn_type; | |
109 typedef const StdPairRng source_range_type; | |
110 | |
111 select_second_const_range(transform_fn_type fn, source_range_type& rng) | |
112 : base(fn, rng) | |
113 { | |
114 } | |
115 | |
116 select_second_const_range(const base& other) : base(other) {} | |
117 }; | |
118 | |
119 template< class StdPairRng > | |
120 inline select_first_range<StdPairRng> | |
121 operator|( const StdPairRng& r, map_keys_forwarder ) | |
122 { | |
123 return operator|( r, | |
124 boost::adaptors::transformed( select_first<StdPairRng>() ) ); | |
125 } | |
126 | |
127 template< class StdPairRng > | |
128 inline select_second_mutable_range<StdPairRng> | |
129 operator|( StdPairRng& r, map_values_forwarder ) | |
130 { | |
131 return operator|( r, | |
132 boost::adaptors::transformed( select_second_mutable<StdPairRng>() ) ); | |
133 } | |
134 | |
135 template< class StdPairRng > | |
136 inline select_second_const_range<StdPairRng> | |
137 operator|( const StdPairRng& r, map_values_forwarder ) | |
138 { | |
139 return operator|( r, | |
140 boost::adaptors::transformed( select_second_const<StdPairRng>() ) ); | |
141 } | |
142 | |
143 } // 'range_detail' | |
144 | |
145 using range_detail::select_first_range; | |
146 using range_detail::select_second_mutable_range; | |
147 using range_detail::select_second_const_range; | |
148 | |
149 namespace adaptors | |
150 { | |
151 namespace | |
152 { | |
153 const range_detail::map_keys_forwarder map_keys = | |
154 range_detail::map_keys_forwarder(); | |
155 | |
156 const range_detail::map_values_forwarder map_values = | |
157 range_detail::map_values_forwarder(); | |
158 } | |
159 | |
160 template<class StdPairRange> | |
161 inline select_first_range<StdPairRange> | |
162 keys(const StdPairRange& rng) | |
163 { | |
164 return select_first_range<StdPairRange>( | |
165 range_detail::select_first<StdPairRange>(), rng ); | |
166 } | |
167 | |
168 template<class StdPairRange> | |
169 inline select_second_const_range<StdPairRange> | |
170 values(const StdPairRange& rng) | |
171 { | |
172 return select_second_const_range<StdPairRange>( | |
173 range_detail::select_second_const<StdPairRange>(), rng ); | |
174 } | |
175 | |
176 template<class StdPairRange> | |
177 inline select_second_mutable_range<StdPairRange> | |
178 values(StdPairRange& rng) | |
179 { | |
180 return select_second_mutable_range<StdPairRange>( | |
181 range_detail::select_second_mutable<StdPairRange>(), rng ); | |
182 } | |
183 } // 'adaptors' | |
184 | |
185 } | |
186 | |
187 #endif |