Chris@16
|
1 /*-----------------------------------------------------------------------------+
|
Chris@16
|
2 Copyright (c) 2010-2010: Joachim Faulhaber
|
Chris@16
|
3 +------------------------------------------------------------------------------+
|
Chris@16
|
4 Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
5 (See accompanying file LICENCE.txt or copy at
|
Chris@16
|
6 http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
7 +-----------------------------------------------------------------------------*/
|
Chris@16
|
8 #ifndef BOOST_ICL_CONCEPT_ELEMENT_MAP_HPP_JOFA_100921
|
Chris@16
|
9 #define BOOST_ICL_CONCEPT_ELEMENT_MAP_HPP_JOFA_100921
|
Chris@16
|
10
|
Chris@16
|
11 #include <boost/mpl/and.hpp>
|
Chris@16
|
12 #include <boost/mpl/not.hpp>
|
Chris@16
|
13 #include <boost/icl/detail/on_absorbtion.hpp>
|
Chris@16
|
14 #include <boost/icl/type_traits/unit_element.hpp>
|
Chris@16
|
15 #include <boost/icl/type_traits/is_total.hpp>
|
Chris@16
|
16 #include <boost/icl/type_traits/absorbs_identities.hpp>
|
Chris@16
|
17 #include <boost/icl/type_traits/is_associative_element_container.hpp>
|
Chris@16
|
18 #include <boost/icl/type_traits/is_combinable.hpp>
|
Chris@16
|
19
|
Chris@16
|
20 #include <boost/icl/concept/map_value.hpp>
|
Chris@16
|
21 #include <boost/icl/detail/map_algo.hpp>
|
Chris@16
|
22
|
Chris@16
|
23
|
Chris@16
|
24 namespace boost{ namespace icl
|
Chris@16
|
25 {
|
Chris@16
|
26
|
Chris@16
|
27 //NOTE: Some forward declarations are needed by some compilers.
|
Chris@16
|
28 template<class Type, class Predicate>
|
Chris@16
|
29 typename enable_if<is_associative_element_container<Type>, Type>::type&
|
Chris@16
|
30 erase_if(const Predicate& pred, Type& object);
|
Chris@16
|
31
|
Chris@16
|
32
|
Chris@16
|
33 //==============================================================================
|
Chris@16
|
34 //= Containedness<ElementMap>
|
Chris@16
|
35 //==============================================================================
|
Chris@16
|
36 //------------------------------------------------------------------------------
|
Chris@16
|
37 //- bool within(c P&, c T&) T:{m} P:{b} fragment_types
|
Chris@16
|
38 //------------------------------------------------------------------------------
|
Chris@16
|
39 /** Checks if a key-value pair is in the map */
|
Chris@16
|
40 template<class Type>
|
Chris@16
|
41 typename enable_if<is_element_map<Type>, bool>::type
|
Chris@16
|
42 within(const typename Type::element_type& value_pair, const Type& super)
|
Chris@16
|
43 {
|
Chris@16
|
44 typedef typename Type::const_iterator const_iterator;
|
Chris@16
|
45 const_iterator found_ = super.find(value_pair.first);
|
Chris@16
|
46 return found_ != super.end() && (*found_).second == value_pair.second;
|
Chris@16
|
47 }
|
Chris@16
|
48
|
Chris@16
|
49 //------------------------------------------------------------------------------
|
Chris@16
|
50 //- bool contains(c T&, c P&) T:{m} P:{b} fragment_types
|
Chris@16
|
51 //------------------------------------------------------------------------------
|
Chris@16
|
52 template<class Type>
|
Chris@16
|
53 typename enable_if<is_element_map<Type>, bool>::type
|
Chris@16
|
54 contains(const Type& super, const typename Type::element_type& value_pair)
|
Chris@16
|
55 {
|
Chris@16
|
56 return icl::within(value_pair, super);
|
Chris@16
|
57 }
|
Chris@16
|
58
|
Chris@16
|
59 //==============================================================================
|
Chris@16
|
60 //= Equivalences and Orderings<ElementMap>
|
Chris@16
|
61 //==============================================================================
|
Chris@16
|
62
|
Chris@16
|
63 /** Protonic equality is equality on all elements that do not carry an identity element as content. */
|
Chris@16
|
64 template<class Type>
|
Chris@16
|
65 inline typename enable_if<is_element_map<Type>, bool>::type
|
Chris@16
|
66 is_distinct_equal(const Type& lhs, const Type& rhs)
|
Chris@16
|
67 {
|
Chris@16
|
68 return Map::lexicographical_distinct_equal(lhs, rhs);
|
Chris@16
|
69 }
|
Chris@16
|
70
|
Chris@16
|
71 //==============================================================================
|
Chris@16
|
72 //= Addition<ElementMap>
|
Chris@16
|
73 //==============================================================================
|
Chris@16
|
74 /** \c add inserts \c value_pair into the map if it's key does
|
Chris@16
|
75 not exist in the map.
|
Chris@16
|
76 If \c value_pairs's key value exists in the map, it's data
|
Chris@16
|
77 value is added to the data value already found in the map. */
|
Chris@16
|
78 template <class Type>
|
Chris@16
|
79 typename enable_if<is_element_map<Type>, Type>::type&
|
Chris@16
|
80 add(Type& object, const typename Type::value_type& value_pair)
|
Chris@16
|
81 {
|
Chris@16
|
82 return object.add(value_pair);
|
Chris@16
|
83 }
|
Chris@16
|
84
|
Chris@16
|
85 /** \c add add \c value_pair into the map using \c prior as a hint to
|
Chris@16
|
86 insert \c value_pair after the position \c prior is pointing to. */
|
Chris@16
|
87 template <class Type>
|
Chris@16
|
88 typename enable_if<is_element_map<Type>, typename Type::iterator>::type
|
Chris@16
|
89 add(Type& object, typename Type::iterator prior,
|
Chris@16
|
90 const typename Type::value_type& value_pair)
|
Chris@16
|
91 {
|
Chris@16
|
92 return object.add(prior, value_pair);
|
Chris@16
|
93 }
|
Chris@16
|
94
|
Chris@16
|
95 //==============================================================================
|
Chris@16
|
96 //= Erasure
|
Chris@16
|
97 //==============================================================================
|
Chris@16
|
98 //------------------------------------------------------------------------------
|
Chris@16
|
99 //- T& erase(T&, c P&) T:{m} P:{b} fragment_type
|
Chris@16
|
100 //------------------------------------------------------------------------------
|
Chris@16
|
101 template <class Type>
|
Chris@16
|
102 typename enable_if<is_element_map<Type>, typename Type::size_type>::type
|
Chris@16
|
103 erase(Type& object, const typename Type::element_type& value_pair)
|
Chris@16
|
104 {
|
Chris@16
|
105 typedef typename Type::size_type size_type;
|
Chris@16
|
106 typedef typename Type::iterator iterator;
|
Chris@16
|
107 typedef typename Type::on_identity_absorbtion on_identity_absorbtion;
|
Chris@16
|
108
|
Chris@16
|
109 if(on_identity_absorbtion::is_absorbable(value_pair.second))
|
Chris@16
|
110 return identity_element<size_type>::value();
|
Chris@16
|
111
|
Chris@16
|
112 iterator it_ = object.find(value_pair.first);
|
Chris@16
|
113 if(it_ != object.end() && value_pair.second == (*it_).second)
|
Chris@16
|
114 {
|
Chris@16
|
115 object.erase(it_);
|
Chris@16
|
116 return unit_element<size_type>::value();
|
Chris@16
|
117 }
|
Chris@16
|
118
|
Chris@16
|
119 return identity_element<size_type>::value();
|
Chris@16
|
120 }
|
Chris@16
|
121
|
Chris@16
|
122 template<class Type>
|
Chris@16
|
123 typename enable_if<is_element_map<Type>, Type>::type&
|
Chris@16
|
124 erase(Type& object, const typename Type::set_type& erasure)
|
Chris@16
|
125 {
|
Chris@16
|
126 typedef typename Type::set_type set_type;
|
Chris@16
|
127 ICL_const_FORALL(typename set_type, elem_, erasure)
|
Chris@16
|
128 icl::erase(object, *elem_);
|
Chris@16
|
129
|
Chris@16
|
130 return object;
|
Chris@16
|
131 }
|
Chris@16
|
132
|
Chris@16
|
133 //==============================================================================
|
Chris@16
|
134 //= Subtraction
|
Chris@16
|
135 //==============================================================================
|
Chris@16
|
136 //------------------------------------------------------------------------------
|
Chris@16
|
137 //- T& subtract(T&, c P&) T:{m} P:{b} fragment_type
|
Chris@16
|
138 //------------------------------------------------------------------------------
|
Chris@16
|
139 template <class Type>
|
Chris@16
|
140 inline typename enable_if<is_element_map<Type>, Type>::type&
|
Chris@16
|
141 subtract(Type& object, const typename Type::element_type& operand)
|
Chris@16
|
142 {
|
Chris@16
|
143 return object.subtract(operand);
|
Chris@16
|
144 }
|
Chris@16
|
145
|
Chris@16
|
146 //------------------------------------------------------------------------------
|
Chris@16
|
147 //- T& subtract(T&, c P&) T:{m} P:{e} key_type
|
Chris@16
|
148 //------------------------------------------------------------------------------
|
Chris@16
|
149 template <class Type>
|
Chris@16
|
150 typename enable_if<is_element_map<Type>, Type>::type&
|
Chris@16
|
151 subtract(Type& object, const typename Type::domain_type& key_value)
|
Chris@16
|
152 {
|
Chris@16
|
153 return icl::erase(object, key_value);
|
Chris@16
|
154 }
|
Chris@16
|
155
|
Chris@16
|
156 //------------------------------------------------------------------------------
|
Chris@16
|
157 //- T& subtract(T&, c P&) T:{m} P:{s} set key_type
|
Chris@16
|
158 //------------------------------------------------------------------------------
|
Chris@16
|
159 template <class Type>
|
Chris@16
|
160 inline typename enable_if<is_element_map<Type>, Type>::type&
|
Chris@16
|
161 operator -= (Type& object, const typename Type::set_type& operand)
|
Chris@16
|
162 {
|
Chris@16
|
163 typedef typename Type::set_type set_type;
|
Chris@16
|
164 typedef typename set_type::const_iterator co_iterator;
|
Chris@16
|
165 typedef typename Type::iterator iterator;
|
Chris@16
|
166
|
Chris@16
|
167 co_iterator common_lwb_, common_upb_;
|
Chris@16
|
168 if(!Set::common_range(common_lwb_, common_upb_, operand, object))
|
Chris@16
|
169 return object;
|
Chris@16
|
170
|
Chris@16
|
171 co_iterator it_ = common_lwb_;
|
Chris@16
|
172 iterator common_;
|
Chris@16
|
173
|
Chris@16
|
174 while(it_ != common_upb_)
|
Chris@16
|
175 object.erase(*it_++);
|
Chris@16
|
176
|
Chris@16
|
177 return object;
|
Chris@16
|
178 }
|
Chris@16
|
179
|
Chris@16
|
180 template <class Type>
|
Chris@16
|
181 inline typename enable_if<is_element_map<Type>, Type>::type
|
Chris@16
|
182 operator - (Type object, const typename Type::set_type& subtrahend)
|
Chris@16
|
183 {
|
Chris@16
|
184 return object -= subtrahend;
|
Chris@16
|
185 }
|
Chris@16
|
186
|
Chris@16
|
187 //==============================================================================
|
Chris@16
|
188 //= Selective Update<ElementMap>
|
Chris@16
|
189 //==============================================================================
|
Chris@16
|
190 //------------------------------------------------------------------------------
|
Chris@16
|
191 //- T& set_at(T&, c P&) T:{m} P:{b}
|
Chris@16
|
192 //------------------------------------------------------------------------------
|
Chris@16
|
193 template<class Type>
|
Chris@16
|
194 inline typename enable_if<is_element_map<Type>, Type>::type&
|
Chris@16
|
195 set_at(Type& object, const typename Type::element_type& operand)
|
Chris@16
|
196 {
|
Chris@16
|
197 typedef typename Type::iterator iterator;
|
Chris@16
|
198 typedef typename Type::codomain_combine codomain_combine;
|
Chris@16
|
199 typedef on_absorbtion<Type,codomain_combine,absorbs_identities<Type>::value>
|
Chris@16
|
200 on_identity_absorbtion;
|
Chris@16
|
201
|
Chris@16
|
202 if(!on_identity_absorbtion::is_absorbable(operand.second))
|
Chris@16
|
203 {
|
Chris@16
|
204 std::pair<iterator,bool> insertion = object.insert(operand);
|
Chris@16
|
205 if(!insertion.second)
|
Chris@16
|
206 insertion->second = operand.second;
|
Chris@16
|
207 }
|
Chris@16
|
208 return object;
|
Chris@16
|
209 }
|
Chris@16
|
210
|
Chris@16
|
211
|
Chris@16
|
212 //==============================================================================
|
Chris@16
|
213 //= Intersection
|
Chris@16
|
214 //==============================================================================
|
Chris@16
|
215 template<class Type>
|
Chris@16
|
216 inline typename enable_if<is_element_map<Type>, void>::type
|
Chris@16
|
217 add_intersection(Type& section, const Type& object,
|
Chris@16
|
218 const typename Type::element_type& operand)
|
Chris@16
|
219 {
|
Chris@16
|
220 object.add_intersection(section, operand);
|
Chris@16
|
221 }
|
Chris@16
|
222
|
Chris@16
|
223 template<class Type>
|
Chris@16
|
224 inline typename enable_if<is_element_map<Type>, void>::type
|
Chris@16
|
225 add_intersection(Type& section, const Type& object, const Type& operand)
|
Chris@16
|
226 {
|
Chris@16
|
227 ICL_const_FORALL(typename Type, it_, operand)
|
Chris@16
|
228 icl::add_intersection(section, object, *it_);
|
Chris@16
|
229 }
|
Chris@16
|
230
|
Chris@16
|
231 //------------------------------------------------------------------------------
|
Chris@16
|
232 //- T& op &=(T&, c P&) T:{m} P:{b m} fragment_types
|
Chris@16
|
233 //------------------------------------------------------------------------------
|
Chris@16
|
234
|
Chris@16
|
235 template<class Type>
|
Chris@16
|
236 inline typename enable_if<mpl::and_<is_element_map<Type>, is_total<Type> >, Type>::type&
|
Chris@16
|
237 operator &=(Type& object, const typename Type::element_type& operand)
|
Chris@16
|
238 {
|
Chris@16
|
239 object.add(operand);
|
Chris@16
|
240 return object;
|
Chris@16
|
241 }
|
Chris@16
|
242
|
Chris@16
|
243 template<class Type>
|
Chris@16
|
244 inline typename enable_if<mpl::and_<is_element_map<Type>, mpl::not_<is_total<Type> > >, Type>::type&
|
Chris@16
|
245 operator &=(Type& object, const typename Type::element_type& operand)
|
Chris@16
|
246 {
|
Chris@16
|
247 Type section;
|
Chris@16
|
248 icl::add_intersection(section, object, operand);
|
Chris@16
|
249 object.swap(section);
|
Chris@16
|
250 return object;
|
Chris@16
|
251 }
|
Chris@16
|
252
|
Chris@16
|
253 template<class Type>
|
Chris@16
|
254 inline typename enable_if<is_element_map<Type>, Type>::type
|
Chris@16
|
255 operator & (Type object, const typename Type::element_type& operand)
|
Chris@16
|
256 {
|
Chris@16
|
257 return object &= operand;
|
Chris@16
|
258 }
|
Chris@16
|
259
|
Chris@16
|
260 template<class Type>
|
Chris@16
|
261 inline typename enable_if<is_element_map<Type>, Type>::type
|
Chris@16
|
262 operator & (const typename Type::element_type& operand, Type object)
|
Chris@16
|
263 {
|
Chris@16
|
264 return object &= operand;
|
Chris@16
|
265 }
|
Chris@16
|
266
|
Chris@16
|
267
|
Chris@16
|
268 template<class Type>
|
Chris@16
|
269 inline typename enable_if<mpl::and_<is_element_map<Type>, is_total<Type> >, Type>::type&
|
Chris@16
|
270 operator &=(Type& object, const Type& operand)
|
Chris@16
|
271 {
|
Chris@16
|
272 object += operand;
|
Chris@16
|
273 return object;
|
Chris@16
|
274 }
|
Chris@16
|
275
|
Chris@16
|
276 template<class Type>
|
Chris@16
|
277 inline typename enable_if<mpl::and_<is_element_map<Type>, mpl::not_<is_total<Type> > >, Type>::type&
|
Chris@16
|
278 operator &=(Type& object, const Type& operand)
|
Chris@16
|
279 {
|
Chris@16
|
280 Type section;
|
Chris@16
|
281 icl::add_intersection(section, object, operand);
|
Chris@16
|
282 object.swap(section);
|
Chris@16
|
283 return object;
|
Chris@16
|
284 }
|
Chris@16
|
285
|
Chris@16
|
286 template<class Type>
|
Chris@16
|
287 inline typename enable_if<is_element_map<Type>, Type>::type
|
Chris@16
|
288 operator & (Type object, const typename Type::key_object_type& operand)
|
Chris@16
|
289 {
|
Chris@16
|
290 return object &= operand;
|
Chris@16
|
291 }
|
Chris@16
|
292
|
Chris@16
|
293 template<class Type>
|
Chris@16
|
294 inline typename enable_if<is_element_map<Type>, Type>::type
|
Chris@16
|
295 operator & (const typename Type::key_object_type& operand, Type object)
|
Chris@16
|
296 {
|
Chris@16
|
297 return object &= operand;
|
Chris@16
|
298 }
|
Chris@16
|
299
|
Chris@16
|
300 //==============================================================================
|
Chris@16
|
301 //= Intersection<ElementMap> bool intersects(x,y)
|
Chris@16
|
302 //==============================================================================
|
Chris@16
|
303 template<class Type, class CoType>
|
Chris@16
|
304 inline typename enable_if< mpl::and_< is_element_map<Type>
|
Chris@16
|
305 , is_total<Type> >
|
Chris@16
|
306 , bool>::type
|
Chris@16
|
307 intersects(const Type&, const CoType&)
|
Chris@16
|
308 {
|
Chris@16
|
309 return true;
|
Chris@16
|
310 }
|
Chris@16
|
311
|
Chris@16
|
312 template<class Type>
|
Chris@16
|
313 inline typename enable_if< mpl::and_< is_element_map<Type>
|
Chris@16
|
314 , mpl::not_<is_total<Type> > >
|
Chris@16
|
315 , bool>::type
|
Chris@16
|
316 intersects(const Type& object, const typename Type::domain_type& operand)
|
Chris@16
|
317 {
|
Chris@16
|
318 return icl::contains(object, operand);
|
Chris@16
|
319 }
|
Chris@16
|
320
|
Chris@16
|
321 template<class Type>
|
Chris@16
|
322 inline typename enable_if< mpl::and_< is_element_map<Type>
|
Chris@16
|
323 , mpl::not_<is_total<Type> > >
|
Chris@16
|
324 , bool>::type
|
Chris@16
|
325 intersects(const Type& object, const typename Type::set_type& operand)
|
Chris@16
|
326 {
|
Chris@16
|
327 if(object.iterative_size() < operand.iterative_size())
|
Chris@16
|
328 return Map::intersects(object, operand);
|
Chris@16
|
329 else
|
Chris@16
|
330 return Map::intersects(operand, object);
|
Chris@16
|
331 }
|
Chris@16
|
332
|
Chris@16
|
333 template<class Type>
|
Chris@16
|
334 inline typename enable_if< mpl::and_< is_element_map<Type>
|
Chris@16
|
335 , mpl::not_<is_total<Type> > >
|
Chris@16
|
336 , bool>::type
|
Chris@16
|
337 intersects(const Type& object, const typename Type::element_type& operand)
|
Chris@16
|
338 {
|
Chris@16
|
339 Type intersection;
|
Chris@16
|
340 icl::add_intersection(intersection, object, operand);
|
Chris@16
|
341 return !intersection.empty();
|
Chris@16
|
342 }
|
Chris@16
|
343
|
Chris@16
|
344 template<class Type>
|
Chris@16
|
345 inline typename enable_if< mpl::and_< is_element_map<Type>
|
Chris@16
|
346 , mpl::not_<is_total<Type> > >
|
Chris@16
|
347 , bool>::type
|
Chris@16
|
348 intersects(const Type& object, const Type& operand)
|
Chris@16
|
349 {
|
Chris@16
|
350 if(object.iterative_size() < operand.iterative_size())
|
Chris@16
|
351 return Map::intersects(object, operand);
|
Chris@16
|
352 else
|
Chris@16
|
353 return Map::intersects(operand, object);
|
Chris@16
|
354 }
|
Chris@16
|
355
|
Chris@16
|
356 //==============================================================================
|
Chris@16
|
357 //= Symmetric difference
|
Chris@16
|
358 //==============================================================================
|
Chris@16
|
359 template<class Type>
|
Chris@16
|
360 inline typename enable_if<is_element_map<Type>, Type>::type&
|
Chris@16
|
361 flip(Type& object, const typename Type::element_type& operand)
|
Chris@16
|
362 {
|
Chris@16
|
363 return object.flip(operand);
|
Chris@16
|
364 }
|
Chris@16
|
365
|
Chris@16
|
366 template<class Type, class CoType>
|
Chris@16
|
367 inline typename enable_if< mpl::and_< is_element_map<Type>
|
Chris@16
|
368 , is_total<Type>
|
Chris@16
|
369 , absorbs_identities<Type> >
|
Chris@16
|
370 , Type>::type&
|
Chris@16
|
371 operator ^= (Type& object, const CoType&)
|
Chris@16
|
372 {
|
Chris@16
|
373 icl::clear(object);
|
Chris@16
|
374 return object;
|
Chris@16
|
375 }
|
Chris@16
|
376
|
Chris@16
|
377 template<class Type>
|
Chris@16
|
378 inline typename enable_if< mpl::and_< is_element_map<Type>
|
Chris@16
|
379 , is_total<Type>
|
Chris@16
|
380 , mpl::not_<absorbs_identities<Type> > >
|
Chris@16
|
381 , Type>::type&
|
Chris@16
|
382 operator ^= (Type& object, const typename Type::element_type& operand)
|
Chris@16
|
383 {
|
Chris@16
|
384 return object.flip(operand);
|
Chris@16
|
385 }
|
Chris@16
|
386
|
Chris@16
|
387 template<class Type>
|
Chris@16
|
388 inline typename enable_if< mpl::and_< is_element_map<Type>
|
Chris@16
|
389 , is_total<Type>
|
Chris@16
|
390 , mpl::not_<absorbs_identities<Type> > >
|
Chris@16
|
391 , Type>::type&
|
Chris@16
|
392 operator ^= (Type& object, const Type& operand)
|
Chris@16
|
393 {
|
Chris@16
|
394 ICL_const_FORALL(typename Type, it_, operand)
|
Chris@16
|
395 icl::flip(object, *it_);
|
Chris@16
|
396
|
Chris@16
|
397 ICL_FORALL(typename Type, it2_, object)
|
Chris@16
|
398 (*it2_).second = identity_element<typename Type::codomain_type>::value();
|
Chris@16
|
399
|
Chris@16
|
400 return object;
|
Chris@16
|
401 }
|
Chris@16
|
402
|
Chris@16
|
403
|
Chris@16
|
404 template<class Type>
|
Chris@16
|
405 inline typename enable_if< mpl::and_< is_element_map<Type>
|
Chris@16
|
406 , mpl::not_<is_total<Type> > >
|
Chris@16
|
407 , Type>::type&
|
Chris@16
|
408 operator ^= (Type& object, const typename Type::element_type& operand)
|
Chris@16
|
409 {
|
Chris@16
|
410 return icl::flip(object, operand);
|
Chris@16
|
411 }
|
Chris@16
|
412
|
Chris@16
|
413 template<class Type>
|
Chris@16
|
414 inline typename enable_if< mpl::and_< is_element_map<Type>
|
Chris@16
|
415 , mpl::not_<is_total<Type> > >
|
Chris@16
|
416 , Type>::type&
|
Chris@16
|
417 operator ^= (Type& object, const Type& operand)
|
Chris@16
|
418 {
|
Chris@16
|
419 typedef typename Type::const_iterator const_iterator;
|
Chris@16
|
420 const_iterator it_ = operand.begin();
|
Chris@16
|
421 while(it_ != operand.end())
|
Chris@16
|
422 icl::flip(object, *it_++);
|
Chris@16
|
423
|
Chris@16
|
424 return object;
|
Chris@16
|
425 }
|
Chris@16
|
426
|
Chris@16
|
427
|
Chris@16
|
428 //==============================================================================
|
Chris@16
|
429 //= Set selection
|
Chris@16
|
430 //==============================================================================
|
Chris@16
|
431 template<class Type>
|
Chris@16
|
432 inline typename enable_if<is_element_map<Type>,
|
Chris@16
|
433 typename Type::set_type>::type&
|
Chris@16
|
434 domain(typename Type::set_type& domain_set, const Type& object)
|
Chris@16
|
435 {
|
Chris@16
|
436 typename Type::set_type::iterator prior_ = domain_set.end();
|
Chris@16
|
437 typename Type::const_iterator it_ = object.begin();
|
Chris@16
|
438 while(it_ != object.end())
|
Chris@16
|
439 prior_ = domain_set.insert(prior_, (*it_++).first);
|
Chris@16
|
440
|
Chris@16
|
441 return domain_set;
|
Chris@16
|
442 }
|
Chris@16
|
443
|
Chris@16
|
444 //==============================================================================
|
Chris@16
|
445 //= Neutron absorbtion
|
Chris@16
|
446 //==============================================================================
|
Chris@16
|
447 template<class Type>
|
Chris@16
|
448 inline typename enable_if<mpl::and_< is_element_map<Type>
|
Chris@16
|
449 , absorbs_identities<Type> >, Type>::type&
|
Chris@16
|
450 absorb_identities(Type& object)
|
Chris@16
|
451 {
|
Chris@16
|
452 typedef typename Type::element_type element_type;
|
Chris@16
|
453 return icl::erase_if(content_is_identity_element<element_type>(), object);
|
Chris@16
|
454 }
|
Chris@16
|
455
|
Chris@16
|
456 template<class Type>
|
Chris@16
|
457 inline typename enable_if<mpl::and_< is_element_map<Type>
|
Chris@16
|
458 , mpl::not_<absorbs_identities<Type> > >
|
Chris@16
|
459 , Type>::type&
|
Chris@16
|
460 absorb_identities(Type&){}
|
Chris@16
|
461
|
Chris@16
|
462 //==============================================================================
|
Chris@16
|
463 //= Streaming<ElementMap>
|
Chris@16
|
464 //==============================================================================
|
Chris@16
|
465 template<class CharType, class CharTraits, class Type>
|
Chris@16
|
466 inline typename enable_if<is_element_map<Type>, std::basic_ostream<CharType, CharTraits> >::type&
|
Chris@16
|
467 operator << (std::basic_ostream<CharType, CharTraits>& stream, const Type& object)
|
Chris@16
|
468 {
|
Chris@16
|
469 stream << "{";
|
Chris@16
|
470 ICL_const_FORALL(typename Type, it, object)
|
Chris@16
|
471 stream << "(" << it->first << "->" << it->second << ")";
|
Chris@16
|
472
|
Chris@16
|
473 return stream << "}";
|
Chris@16
|
474 }
|
Chris@16
|
475
|
Chris@16
|
476
|
Chris@16
|
477 }} // namespace boost icl
|
Chris@16
|
478
|
Chris@16
|
479 #endif
|
Chris@16
|
480
|
Chris@16
|
481
|