Imported Upstream version 1.57.0
[platform/upstream/boost.git] / boost / foreach.hpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // foreach.hpp header file
3 //
4 // Copyright 2004 Eric Niebler.
5 // Distributed under the Boost Software License, Version 1.0. (See
6 // accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 // See http://www.boost.org/libs/foreach for documentation
9 //
10 // Credits:
11 //  Anson Tsao        - for the initial inspiration and several good suggestions.
12 //  Thorsten Ottosen  - for Boost.Range, and for suggesting a way to detect
13 //                      const-qualified rvalues at compile time on VC7.1+
14 //  Russell Hind      - For help porting to Borland
15 //  Alisdair Meredith - For help porting to Borland
16 //  Stefan Slapeta    - For help porting to Intel
17 //  David Jenkins     - For help finding a Microsoft Code Analysis bug
18 //  mimomorin@...     - For a patch to use rvalue refs on supporting compilers
19
20 #ifndef BOOST_FOREACH
21
22 // MS compatible compilers support #pragma once
23 #if defined(_MSC_VER)
24 # pragma once
25 #endif
26
27 #include <cstddef>
28 #include <utility>  // for std::pair
29
30 #include <boost/config.hpp>
31 #include <boost/detail/workaround.hpp>
32
33 // Some compilers let us detect even const-qualified rvalues at compile-time
34 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)                                                   \
35  || defined(BOOST_MSVC) && !defined(_PREFAST_)                                 \
36  || (BOOST_WORKAROUND(__GNUC__, == 4) && (__GNUC_MINOR__ <= 5) && !defined(BOOST_INTEL) &&       \
37                                                                   !defined(BOOST_CLANG))         \
38  || (BOOST_WORKAROUND(__GNUC__, == 3) && (__GNUC_MINOR__ >= 4) && !defined(BOOST_INTEL) &&       \
39                                                                   !defined(BOOST_CLANG))
40 # define BOOST_FOREACH_COMPILE_TIME_CONST_RVALUE_DETECTION
41 #else
42 // Some compilers allow temporaries to be bound to non-const references.
43 // These compilers make it impossible to for BOOST_FOREACH to detect
44 // temporaries and avoid reevaluation of the collection expression.
45 # if BOOST_WORKAROUND(__BORLANDC__, < 0x593)                                                    \
46   || (BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 700) && defined(_MSC_VER))                   \
47   || BOOST_WORKAROUND(__SUNPRO_CC, < 0x5100)                                                    \
48   || BOOST_WORKAROUND(__DECCXX_VER, <= 60590042)
49 #  define BOOST_FOREACH_NO_RVALUE_DETECTION
50 # endif
51 // Some compilers do not correctly implement the lvalue/rvalue conversion
52 // rules of the ternary conditional operator.
53 # if defined(BOOST_FOREACH_NO_RVALUE_DETECTION)                                                 \
54   || defined(BOOST_NO_SFINAE)                                                                   \
55   || BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1400))                                        \
56   || BOOST_WORKAROUND(BOOST_INTEL_WIN, BOOST_TESTED_AT(1400))                                   \
57   || (BOOST_WORKAROUND(__GNUC__, == 3) && (__GNUC_MINOR__ <= 3) && defined(__APPLE_CC__))       \
58   || BOOST_WORKAROUND(__IBMCPP__, BOOST_TESTED_AT(600))                                         \
59   || BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206))                                      \
60   || BOOST_WORKAROUND(__SUNPRO_CC, >= 0x5100)                                                   \
61   || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x590))
62 #  define BOOST_FOREACH_NO_CONST_RVALUE_DETECTION
63 # else
64 #  define BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION
65 # endif
66 #endif
67
68 #include <boost/mpl/if.hpp>
69 #include <boost/mpl/assert.hpp>
70 #include <boost/mpl/logical.hpp>
71 #include <boost/mpl/eval_if.hpp>
72 #include <boost/noncopyable.hpp>
73 #include <boost/range/end.hpp>
74 #include <boost/range/begin.hpp>
75 #include <boost/range/rend.hpp>
76 #include <boost/range/rbegin.hpp>
77 #include <boost/range/iterator.hpp>
78 #include <boost/range/reverse_iterator.hpp>
79 #include <boost/type_traits/is_array.hpp>
80 #include <boost/type_traits/is_const.hpp>
81 #include <boost/type_traits/is_abstract.hpp>
82 #include <boost/type_traits/is_base_and_derived.hpp>
83 #include <boost/type_traits/is_rvalue_reference.hpp>
84 #include <boost/iterator/iterator_traits.hpp>
85 #include <boost/utility/addressof.hpp>
86 #include <boost/foreach_fwd.hpp>
87
88 #ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION
89 # include <new>
90 # include <boost/aligned_storage.hpp>
91 # include <boost/utility/enable_if.hpp>
92 # include <boost/type_traits/remove_const.hpp>
93 #endif
94
95 namespace boost
96 {
97
98 // forward declarations for iterator_range
99 template<typename T>
100 class iterator_range;
101
102 // forward declarations for sub_range
103 template<typename T>
104 class sub_range;
105
106 namespace foreach
107 {
108     ///////////////////////////////////////////////////////////////////////////////
109     // in_range
110     //
111     template<typename T>
112     inline std::pair<T, T> in_range(T begin, T end)
113     {
114         return std::make_pair(begin, end);
115     }
116
117     ///////////////////////////////////////////////////////////////////////////////
118     // boost::foreach::is_lightweight_proxy
119     //   Specialize this for user-defined collection types if they are inexpensive to copy.
120     //   This tells BOOST_FOREACH it can avoid the rvalue/lvalue detection stuff.
121     template<typename T>
122     struct is_lightweight_proxy
123       : boost::mpl::false_
124     {
125     };
126
127     ///////////////////////////////////////////////////////////////////////////////
128     // boost::foreach::is_noncopyable
129     //   Specialize this for user-defined collection types if they cannot be copied.
130     //   This also tells BOOST_FOREACH to avoid the rvalue/lvalue detection stuff.
131     template<typename T>
132     struct is_noncopyable
133     #if !defined(BOOST_BROKEN_IS_BASE_AND_DERIVED) && !defined(BOOST_NO_IS_ABSTRACT)
134       : boost::mpl::or_<
135             boost::is_abstract<T>
136           , boost::is_base_and_derived<boost::noncopyable, T>
137         >
138     #elif !defined(BOOST_BROKEN_IS_BASE_AND_DERIVED)
139       : boost::is_base_and_derived<boost::noncopyable, T>
140     #elif !defined(BOOST_NO_IS_ABSTRACT)
141       : boost::is_abstract<T>
142     #else
143       : boost::mpl::false_
144     #endif
145     {
146     };
147
148 } // namespace foreach
149
150 } // namespace boost
151
152 // vc6/7 needs help ordering the following overloads
153 #ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
154 # define BOOST_FOREACH_TAG_DEFAULT ...
155 #else
156 # define BOOST_FOREACH_TAG_DEFAULT boost::foreach::tag
157 #endif
158
159 ///////////////////////////////////////////////////////////////////////////////
160 // boost_foreach_is_lightweight_proxy
161 //   Another customization point for the is_lightweight_proxy optimization,
162 //   this one works on legacy compilers. Overload boost_foreach_is_lightweight_proxy
163 //   at the global namespace for your type.
164 template<typename T>
165 inline boost::foreach::is_lightweight_proxy<T> *
166 boost_foreach_is_lightweight_proxy(T *&, BOOST_FOREACH_TAG_DEFAULT) { return 0; }
167
168 template<typename T>
169 inline boost::mpl::true_ *
170 boost_foreach_is_lightweight_proxy(std::pair<T, T> *&, boost::foreach::tag) { return 0; }
171
172 template<typename T>
173 inline boost::mpl::true_ *
174 boost_foreach_is_lightweight_proxy(boost::iterator_range<T> *&, boost::foreach::tag) { return 0; }
175
176 template<typename T>
177 inline boost::mpl::true_ *
178 boost_foreach_is_lightweight_proxy(boost::sub_range<T> *&, boost::foreach::tag) { return 0; }
179
180 template<typename T>
181 inline boost::mpl::true_ *
182 boost_foreach_is_lightweight_proxy(T **&, boost::foreach::tag) { return 0; }
183
184 ///////////////////////////////////////////////////////////////////////////////
185 // boost_foreach_is_noncopyable
186 //   Another customization point for the is_noncopyable trait,
187 //   this one works on legacy compilers. Overload boost_foreach_is_noncopyable
188 //   at the global namespace for your type.
189 template<typename T>
190 inline boost::foreach::is_noncopyable<T> *
191 boost_foreach_is_noncopyable(T *&, BOOST_FOREACH_TAG_DEFAULT) { return 0; }
192
193 namespace boost
194 {
195
196 namespace foreach_detail_
197 {
198
199 ///////////////////////////////////////////////////////////////////////////////
200 // Define some utilities for assessing the properties of expressions
201 //
202 template<typename Bool1, typename Bool2>
203 inline boost::mpl::and_<Bool1, Bool2> *and_(Bool1 *, Bool2 *) { return 0; }
204
205 template<typename Bool1, typename Bool2, typename Bool3>
206 inline boost::mpl::and_<Bool1, Bool2, Bool3> *and_(Bool1 *, Bool2 *, Bool3 *) { return 0; }
207
208 template<typename Bool1, typename Bool2>
209 inline boost::mpl::or_<Bool1, Bool2> *or_(Bool1 *, Bool2 *) { return 0; }
210
211 template<typename Bool1, typename Bool2, typename Bool3>
212 inline boost::mpl::or_<Bool1, Bool2, Bool3> *or_(Bool1 *, Bool2 *, Bool3 *) { return 0; }
213
214 template<typename Bool1>
215 inline boost::mpl::not_<Bool1> *not_(Bool1 *) { return 0; }
216
217 template<typename T>
218 inline boost::is_array<T> *is_array_(T const &) { return 0; }
219
220 template<typename T>
221 inline boost::is_const<T> *is_const_(T &) { return 0; }
222
223 #ifndef BOOST_FOREACH_NO_RVALUE_DETECTION
224 template<typename T>
225 inline boost::mpl::true_ *is_const_(T const &) { return 0; }
226 #endif
227
228 #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
229 template<typename T>
230 inline boost::mpl::false_ *is_rvalue_(T &, int) { return 0; }
231
232 template<typename T>
233 inline boost::mpl::true_ *is_rvalue_(T const &, ...) { return 0; }
234 #else
235 template<typename T>
236 inline boost::is_rvalue_reference<T &&> *is_rvalue_(T &&, int) { return 0; }
237 #endif
238
239 ///////////////////////////////////////////////////////////////////////////////
240 // auto_any_t/auto_any
241 //  General utility for putting an object of any type into automatic storage
242 struct auto_any_base
243 {
244     // auto_any_base must evaluate to false in boolean context so that
245     // they can be declared in if() statements.
246     operator bool() const
247     {
248         return false;
249     }
250 };
251
252 template<typename T>
253 struct auto_any : auto_any_base
254 {
255     explicit auto_any(T const &t)
256       : item(t)
257     {
258     }
259
260     // temporaries of type auto_any will be bound to const auto_any_base
261     // references, but we still want to be able to mutate the stored
262     // data, so declare it as mutable.
263     mutable T item;
264 };
265
266 typedef auto_any_base const &auto_any_t;
267
268 template<typename T, typename C>
269 inline BOOST_DEDUCED_TYPENAME boost::mpl::if_<C, T const, T>::type &auto_any_cast(auto_any_t a)
270 {
271     return static_cast<auto_any<T> const &>(a).item;
272 }
273
274 typedef boost::mpl::true_ const_;
275
276 ///////////////////////////////////////////////////////////////////////////////
277 // type2type
278 //
279 template<typename T, typename C = boost::mpl::false_>
280 struct type2type
281   : boost::mpl::if_<C, T const, T>
282 {
283 };
284
285 template<typename T>
286 struct wrap_cstr
287 {
288     typedef T type;
289 };
290
291 template<>
292 struct wrap_cstr<char *>
293 {
294     typedef wrap_cstr<char *> type;
295     typedef char *iterator;
296     typedef char *const_iterator;
297 };
298
299 template<>
300 struct wrap_cstr<char const *>
301 {
302     typedef wrap_cstr<char const *> type;
303     typedef char const *iterator;
304     typedef char const *const_iterator;
305 };
306
307 template<>
308 struct wrap_cstr<wchar_t *>
309 {
310     typedef wrap_cstr<wchar_t *> type;
311     typedef wchar_t *iterator;
312     typedef wchar_t *const_iterator;
313 };
314
315 template<>
316 struct wrap_cstr<wchar_t const *>
317 {
318     typedef wrap_cstr<wchar_t const *> type;
319     typedef wchar_t const *iterator;
320     typedef wchar_t const *const_iterator;
321 };
322
323 template<typename T>
324 struct is_char_array
325   : mpl::and_<
326         is_array<T>
327       , mpl::or_<
328             is_convertible<T, char const *>
329           , is_convertible<T, wchar_t const *>
330         >
331     >
332 {};
333
334 template<typename T, typename C = boost::mpl::false_>
335 struct foreach_iterator
336 {
337     // **** READ THIS IF YOUR COMPILE BREAKS HERE ****
338     //
339     // There is an ambiguity about how to iterate over arrays of char and wchar_t. 
340     // Should the last array element be treated as a null terminator to be skipped, or
341     // is it just like any other element in the array? To fix the problem, you must
342     // say which behavior you want.
343     //
344     // To treat the container as a null-terminated string, merely cast it to a
345     // char const *, as in BOOST_FOREACH( char ch, (char const *)"hello" ) ...
346     //
347     // To treat the container as an array, use boost::as_array() in <boost/range/as_array.hpp>,
348     // as in BOOST_FOREACH( char ch, boost::as_array("hello") ) ...
349     BOOST_MPL_ASSERT_MSG( (!is_char_array<T>::value), IS_THIS_AN_ARRAY_OR_A_NULL_TERMINATED_STRING, (T&) );
350
351     // If the type is a pointer to a null terminated string (as opposed 
352     // to an array type), there is no ambiguity.
353     typedef BOOST_DEDUCED_TYPENAME wrap_cstr<T>::type container;
354
355     typedef BOOST_DEDUCED_TYPENAME boost::mpl::eval_if<
356         C
357       , range_const_iterator<container>
358       , range_mutable_iterator<container>
359     >::type type;
360 };
361
362
363 template<typename T, typename C = boost::mpl::false_>
364 struct foreach_reverse_iterator
365 {
366     // **** READ THIS IF YOUR COMPILE BREAKS HERE ****
367     //
368     // There is an ambiguity about how to iterate over arrays of char and wchar_t. 
369     // Should the last array element be treated as a null terminator to be skipped, or
370     // is it just like any other element in the array? To fix the problem, you must
371     // say which behavior you want.
372     //
373     // To treat the container as a null-terminated string, merely cast it to a
374     // char const *, as in BOOST_FOREACH( char ch, (char const *)"hello" ) ...
375     //
376     // To treat the container as an array, use boost::as_array() in <boost/range/as_array.hpp>,
377     // as in BOOST_FOREACH( char ch, boost::as_array("hello") ) ...
378     BOOST_MPL_ASSERT_MSG( (!is_char_array<T>::value), IS_THIS_AN_ARRAY_OR_A_NULL_TERMINATED_STRING, (T&) );
379
380     // If the type is a pointer to a null terminated string (as opposed 
381     // to an array type), there is no ambiguity.
382     typedef BOOST_DEDUCED_TYPENAME wrap_cstr<T>::type container;
383
384     typedef BOOST_DEDUCED_TYPENAME boost::mpl::eval_if<
385         C
386       , range_reverse_iterator<container const>
387       , range_reverse_iterator<container>
388     >::type type;
389 };
390
391 template<typename T, typename C = boost::mpl::false_>
392 struct foreach_reference
393   : iterator_reference<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>
394 {
395 };
396
397 ///////////////////////////////////////////////////////////////////////////////
398 // encode_type
399 //
400 template<typename T>
401 inline type2type<T> *encode_type(T &, boost::mpl::false_ *) { return 0; }
402
403 template<typename T>
404 inline type2type<T, const_> *encode_type(T const &, boost::mpl::true_ *) { return 0; }
405
406 ///////////////////////////////////////////////////////////////////////////////
407 // set_false
408 //
409 inline bool set_false(bool &b)
410 {
411     b = false;
412     return false;
413 }
414
415 ///////////////////////////////////////////////////////////////////////////////
416 // to_ptr
417 //
418 template<typename T>
419 inline T *&to_ptr(T const &)
420 {
421     static T *t = 0;
422     return t;
423 }
424
425 // Borland needs a little extra help with arrays
426 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
427 template<typename T,std::size_t N>
428 inline T (*&to_ptr(T (&)[N]))[N]
429 {
430     static T (*t)[N] = 0;
431     return t;
432 }
433
434 ///////////////////////////////////////////////////////////////////////////////
435 // derefof
436 //
437 template<typename T>
438 inline T &derefof(T *t)
439 {
440     // This is a work-around for a compiler bug in Borland. If T* is a pointer to array type U(*)[N],
441     // then dereferencing it results in a U* instead of U(&)[N]. The cast forces the issue.
442     return reinterpret_cast<T &>(
443         *const_cast<char *>(
444             reinterpret_cast<char const volatile *>(t)
445         )
446     );
447 }
448
449 # define BOOST_FOREACH_DEREFOF(T) boost::foreach_detail_::derefof(*T)
450 #else
451 # define BOOST_FOREACH_DEREFOF(T) (*T)
452 #endif
453
454 #if defined(BOOST_FOREACH_COMPILE_TIME_CONST_RVALUE_DETECTION)                                  \
455  && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
456 ///////////////////////////////////////////////////////////////////////////////
457 // Rvalue references makes it drop-dead simple to detect at compile time
458 // whether an expression is an rvalue.
459 ///////////////////////////////////////////////////////////////////////////////
460
461 # define BOOST_FOREACH_IS_RVALUE(COL)                                                           \
462     boost::foreach_detail_::is_rvalue_((COL), 0)
463
464 #elif defined(BOOST_FOREACH_COMPILE_TIME_CONST_RVALUE_DETECTION)                                \
465  && defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
466 ///////////////////////////////////////////////////////////////////////////////
467 // Detect at compile-time whether an expression yields an rvalue or
468 // an lvalue. This is rather non-standard, but some popular compilers
469 // accept it.
470 ///////////////////////////////////////////////////////////////////////////////
471
472 ///////////////////////////////////////////////////////////////////////////////
473 // rvalue_probe
474 //
475 template<typename T>
476 struct rvalue_probe
477 {
478     struct private_type_ {};
479     // can't ever return an array by value
480     typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_<
481         boost::mpl::or_<boost::is_abstract<T>, boost::is_array<T> >, private_type_, T
482     >::type value_type;
483     operator value_type() { return *reinterpret_cast<value_type *>(this); } // never called
484     operator T &() const { return *reinterpret_cast<T *>(const_cast<rvalue_probe *>(this)); } // never called
485 };
486
487 template<typename T>
488 rvalue_probe<T> const make_probe(T const &)
489 {
490     return rvalue_probe<T>();
491 }
492
493 # define BOOST_FOREACH_IS_RVALUE(COL)                                                           \
494     boost::foreach_detail_::and_(                                                               \
495         boost::foreach_detail_::not_(boost::foreach_detail_::is_array_(COL))                    \
496       , (true ? 0 : boost::foreach_detail_::is_rvalue_(                                         \
497             (true ? boost::foreach_detail_::make_probe(COL) : (COL)), 0)))
498
499 #elif defined(BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION)
500 ///////////////////////////////////////////////////////////////////////////////
501 // Detect at run-time whether an expression yields an rvalue
502 // or an lvalue. This is 100% standard C++, but not all compilers
503 // accept it. Also, it causes FOREACH to break when used with non-
504 // copyable collection types.
505 ///////////////////////////////////////////////////////////////////////////////
506
507 ///////////////////////////////////////////////////////////////////////////////
508 // rvalue_probe
509 //
510 template<typename T>
511 struct rvalue_probe
512 {
513     rvalue_probe(T &t, bool &b)
514       : value(t)
515       , is_rvalue(b)
516     {
517     }
518
519     struct private_type_ {};
520     // can't ever return an array or an abstract type by value
521     #ifdef BOOST_NO_IS_ABSTRACT
522     typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_<
523         boost::is_array<T>, private_type_, T
524     >::type value_type;
525     #else
526     typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_<
527         boost::mpl::or_<boost::is_abstract<T>, boost::is_array<T> >, private_type_, T
528     >::type value_type;
529     #endif
530     
531     operator value_type()
532     {
533         this->is_rvalue = true;
534         return this->value;
535     }
536
537     operator T &() const
538     {
539         return this->value;
540     }
541
542 private:
543     T &value;
544     bool &is_rvalue;
545 };
546
547 template<typename T>
548 rvalue_probe<T> make_probe(T &t, bool &b) { return rvalue_probe<T>(t, b); }
549
550 template<typename T>
551 rvalue_probe<T const> make_probe(T const &t, bool &b)  { return rvalue_probe<T const>(t, b); }
552
553 ///////////////////////////////////////////////////////////////////////////////
554 // simple_variant
555 //  holds either a T or a T const*
556 template<typename T>
557 struct simple_variant
558 {
559     simple_variant(T const *t)
560       : is_rvalue(false)
561     {
562         *static_cast<T const **>(this->data.address()) = t;
563     }
564
565     simple_variant(T const &t)
566       : is_rvalue(true)
567     {
568         ::new(this->data.address()) T(t);
569     }
570
571     simple_variant(simple_variant const &that)
572       : is_rvalue(that.is_rvalue)
573     {
574         if(this->is_rvalue)
575             ::new(this->data.address()) T(*that.get());
576         else
577             *static_cast<T const **>(this->data.address()) = that.get();
578     }
579
580     ~simple_variant()
581     {
582         if(this->is_rvalue)
583             this->get()->~T();
584     }
585
586     T const *get() const
587     {
588         if(this->is_rvalue)
589             return static_cast<T const *>(this->data.address());
590         else
591             return *static_cast<T const * const *>(this->data.address());
592     }
593
594 private:
595     enum size_type { size = sizeof(T) > sizeof(T*) ? sizeof(T) : sizeof(T*) };
596     simple_variant &operator =(simple_variant const &); 
597     bool const is_rvalue;
598     aligned_storage<size> data;
599 };
600
601 // If the collection is an array or is noncopyable, it must be an lvalue.
602 // If the collection is a lightweight proxy, treat it as an rvalue
603 // BUGBUG what about a noncopyable proxy?
604 template<typename LValue, typename IsProxy>
605 inline BOOST_DEDUCED_TYPENAME boost::enable_if<boost::mpl::or_<LValue, IsProxy>, IsProxy>::type *
606 should_copy_impl(LValue *, IsProxy *, bool *)
607 {
608     return 0;
609 }
610
611 // Otherwise, we must determine at runtime whether it's an lvalue or rvalue
612 inline bool *
613 should_copy_impl(boost::mpl::false_ *, boost::mpl::false_ *, bool *is_rvalue)
614 {
615     return is_rvalue;
616 }
617
618 #endif
619
620 ///////////////////////////////////////////////////////////////////////////////
621 // contain
622 //
623 template<typename T>
624 inline auto_any<T> contain(T const &t, boost::mpl::true_ *) // rvalue
625 {
626     return auto_any<T>(t);
627 }
628
629 template<typename T>
630 inline auto_any<T *> contain(T &t, boost::mpl::false_ *) // lvalue
631 {
632     // Cannot seem to get sunpro to handle addressof() with array types.
633     #if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x570))
634     return auto_any<T *>(&t);
635     #else
636     return auto_any<T *>(boost::addressof(t));
637     #endif
638 }
639
640 #ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION
641 template<typename T>
642 inline auto_any<simple_variant<T> >
643 contain(T const &t, bool *rvalue)
644 {
645     return auto_any<simple_variant<T> >(*rvalue ? simple_variant<T>(t) : simple_variant<T>(&t));
646 }
647 #endif
648
649 /////////////////////////////////////////////////////////////////////////////
650 // begin
651 //
652 template<typename T, typename C>
653 inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>
654 begin(auto_any_t col, type2type<T, C> *, boost::mpl::true_ *) // rvalue
655 {
656     return auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>(
657         boost::begin(auto_any_cast<T, C>(col)));
658 }
659
660 template<typename T, typename C>
661 inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>
662 begin(auto_any_t col, type2type<T, C> *, boost::mpl::false_ *) // lvalue
663 {
664     typedef BOOST_DEDUCED_TYPENAME type2type<T, C>::type type;
665     typedef BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type iterator;
666     return auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>(
667         iterator(boost::begin(BOOST_FOREACH_DEREFOF((auto_any_cast<type *, boost::mpl::false_>(col))))));
668 }
669
670 #ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION
671 template<typename T>
672 inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, const_>::type>
673 begin(auto_any_t col, type2type<T, const_> *, bool *)
674 {
675     return auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, const_>::type>(
676         boost::begin(*auto_any_cast<simple_variant<T>, boost::mpl::false_>(col).get()));
677 }
678 #endif
679
680 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
681 template<typename T, typename C>
682 inline auto_any<T *>
683 begin(auto_any_t col, type2type<T *, C> *, boost::mpl::true_ *) // null-terminated C-style strings
684 {
685     return auto_any<T *>(auto_any_cast<T *, boost::mpl::false_>(col));
686 }
687 #endif
688
689 ///////////////////////////////////////////////////////////////////////////////
690 // end
691 //
692 template<typename T, typename C>
693 inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>
694 end(auto_any_t col, type2type<T, C> *, boost::mpl::true_ *) // rvalue
695 {
696     return auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>(
697         boost::end(auto_any_cast<T, C>(col)));
698 }
699
700 template<typename T, typename C>
701 inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>
702 end(auto_any_t col, type2type<T, C> *, boost::mpl::false_ *) // lvalue
703 {
704     typedef BOOST_DEDUCED_TYPENAME type2type<T, C>::type type;
705     typedef BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type iterator;
706     return auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>(
707         iterator(boost::end(BOOST_FOREACH_DEREFOF((auto_any_cast<type *, boost::mpl::false_>(col))))));
708 }
709
710 #ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION
711 template<typename T>
712 inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, const_>::type>
713 end(auto_any_t col, type2type<T, const_> *, bool *)
714 {
715     return auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, const_>::type>(
716         boost::end(*auto_any_cast<simple_variant<T>, boost::mpl::false_>(col).get()));
717 }
718 #endif
719
720 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
721 template<typename T, typename C>
722 inline auto_any<int>
723 end(auto_any_t, type2type<T *, C> *, boost::mpl::true_ *) // null-terminated C-style strings
724 {
725     return auto_any<int>(0); // not used
726 }
727 #endif
728
729 ///////////////////////////////////////////////////////////////////////////////
730 // done
731 //
732 template<typename T, typename C>
733 inline bool done(auto_any_t cur, auto_any_t end, type2type<T, C> *)
734 {
735     typedef BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type iter_t;
736     return auto_any_cast<iter_t, boost::mpl::false_>(cur) == auto_any_cast<iter_t, boost::mpl::false_>(end);
737 }
738
739 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
740 template<typename T, typename C>
741 inline bool done(auto_any_t cur, auto_any_t, type2type<T *, C> *) // null-terminated C-style strings
742 {
743     return ! *auto_any_cast<T *, boost::mpl::false_>(cur);
744 }
745 #endif
746
747 ///////////////////////////////////////////////////////////////////////////////
748 // next
749 //
750 template<typename T, typename C>
751 inline void next(auto_any_t cur, type2type<T, C> *)
752 {
753     typedef BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type iter_t;
754     ++auto_any_cast<iter_t, boost::mpl::false_>(cur);
755 }
756
757 ///////////////////////////////////////////////////////////////////////////////
758 // deref
759 //
760 template<typename T, typename C>
761 inline BOOST_DEDUCED_TYPENAME foreach_reference<T, C>::type
762 deref(auto_any_t cur, type2type<T, C> *)
763 {
764     typedef BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type iter_t;
765     return *auto_any_cast<iter_t, boost::mpl::false_>(cur);
766 }
767
768 /////////////////////////////////////////////////////////////////////////////
769 // rbegin
770 //
771 template<typename T, typename C>
772 inline auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type>
773 rbegin(auto_any_t col, type2type<T, C> *, boost::mpl::true_ *) // rvalue
774 {
775     return auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type>(
776         boost::rbegin(auto_any_cast<T, C>(col)));
777 }
778
779 template<typename T, typename C>
780 inline auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type>
781 rbegin(auto_any_t col, type2type<T, C> *, boost::mpl::false_ *) // lvalue
782 {
783     typedef BOOST_DEDUCED_TYPENAME type2type<T, C>::type type;
784     typedef BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type iterator;
785     return auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type>(
786         iterator(boost::rbegin(BOOST_FOREACH_DEREFOF((auto_any_cast<type *, boost::mpl::false_>(col))))));
787 }
788
789 #ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION
790 template<typename T>
791 inline auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, const_>::type>
792 rbegin(auto_any_t col, type2type<T, const_> *, bool *)
793 {
794     return auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, const_>::type>(
795         boost::rbegin(*auto_any_cast<simple_variant<T>, boost::mpl::false_>(col).get()));
796 }
797 #endif
798
799 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
800 template<typename T, typename C>
801 inline auto_any<reverse_iterator<T *> >
802 rbegin(auto_any_t col, type2type<T *, C> *, boost::mpl::true_ *) // null-terminated C-style strings
803 {
804     T *p = auto_any_cast<T *, boost::mpl::false_>(col);
805     while(0 != *p)
806         ++p;
807     return auto_any<reverse_iterator<T *> >(reverse_iterator<T *>(p));
808 }
809 #endif
810
811 ///////////////////////////////////////////////////////////////////////////////
812 // rend
813 //
814 template<typename T, typename C>
815 inline auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type>
816 rend(auto_any_t col, type2type<T, C> *, boost::mpl::true_ *) // rvalue
817 {
818     return auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type>(
819         boost::rend(auto_any_cast<T, C>(col)));
820 }
821
822 template<typename T, typename C>
823 inline auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type>
824 rend(auto_any_t col, type2type<T, C> *, boost::mpl::false_ *) // lvalue
825 {
826     typedef BOOST_DEDUCED_TYPENAME type2type<T, C>::type type;
827     typedef BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type iterator;
828     return auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type>(
829         iterator(boost::rend(BOOST_FOREACH_DEREFOF((auto_any_cast<type *, boost::mpl::false_>(col))))));
830 }
831
832 #ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION
833 template<typename T>
834 inline auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, const_>::type>
835 rend(auto_any_t col, type2type<T, const_> *, bool *)
836 {
837     return auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, const_>::type>(
838         boost::rend(*auto_any_cast<simple_variant<T>, boost::mpl::false_>(col).get()));
839 }
840 #endif
841
842 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
843 template<typename T, typename C>
844 inline auto_any<reverse_iterator<T *> >
845 rend(auto_any_t col, type2type<T *, C> *, boost::mpl::true_ *) // null-terminated C-style strings
846 {
847     return auto_any<reverse_iterator<T *> >(
848         reverse_iterator<T *>(auto_any_cast<T *, boost::mpl::false_>(col)));
849 }
850 #endif
851
852 ///////////////////////////////////////////////////////////////////////////////
853 // rdone
854 //
855 template<typename T, typename C>
856 inline bool rdone(auto_any_t cur, auto_any_t end, type2type<T, C> *)
857 {
858     typedef BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type iter_t;
859     return auto_any_cast<iter_t, boost::mpl::false_>(cur) == auto_any_cast<iter_t, boost::mpl::false_>(end);
860 }
861
862 ///////////////////////////////////////////////////////////////////////////////
863 // rnext
864 //
865 template<typename T, typename C>
866 inline void rnext(auto_any_t cur, type2type<T, C> *)
867 {
868     typedef BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type iter_t;
869     ++auto_any_cast<iter_t, boost::mpl::false_>(cur);
870 }
871
872 ///////////////////////////////////////////////////////////////////////////////
873 // rderef
874 //
875 template<typename T, typename C>
876 inline BOOST_DEDUCED_TYPENAME foreach_reference<T, C>::type
877 rderef(auto_any_t cur, type2type<T, C> *)
878 {
879     typedef BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type iter_t;
880     return *auto_any_cast<iter_t, boost::mpl::false_>(cur);
881 }
882
883 } // namespace foreach_detail_
884 } // namespace boost
885
886 // Suppress a bogus code analysis warning on vc8+
887 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
888 # define BOOST_FOREACH_SUPPRESS_WARNINGS() __pragma(warning(suppress:6001))
889 #else
890 # define BOOST_FOREACH_SUPPRESS_WARNINGS()
891 #endif
892
893 ///////////////////////////////////////////////////////////////////////////////
894 // Define a macro for giving hidden variables a unique name. Not strictly
895 // needed, but eliminates some warnings on some compilers.
896 #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
897 // With some versions of MSVC, use of __LINE__ to create unique identifiers
898 // can fail when the Edit-and-Continue debug flag is used.
899 # define BOOST_FOREACH_ID(x) x
900 #else
901 # define BOOST_FOREACH_ID(x) BOOST_PP_CAT(x, __LINE__)
902 #endif
903
904 // A sneaky way to get the type of the collection without evaluating the expression
905 #define BOOST_FOREACH_TYPEOF(COL)                                                               \
906     (true ? 0 : boost::foreach_detail_::encode_type(COL, boost::foreach_detail_::is_const_(COL)))
907
908 // returns true_* if the type is noncopyable
909 #define BOOST_FOREACH_IS_NONCOPYABLE(COL)                                                       \
910     boost_foreach_is_noncopyable(                                                               \
911         boost::foreach_detail_::to_ptr(COL)                                                     \
912       , boost_foreach_argument_dependent_lookup_hack_value)
913
914 // returns true_* if the type is a lightweight proxy (and is not noncopyable)
915 #define BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(COL)                                                 \
916     boost::foreach_detail_::and_(                                                               \
917         boost::foreach_detail_::not_(BOOST_FOREACH_IS_NONCOPYABLE(COL))                         \
918       , boost_foreach_is_lightweight_proxy(                                                     \
919             boost::foreach_detail_::to_ptr(COL)                                                 \
920           , boost_foreach_argument_dependent_lookup_hack_value))
921
922 #if defined(BOOST_FOREACH_COMPILE_TIME_CONST_RVALUE_DETECTION)
923 ///////////////////////////////////////////////////////////////////////////////
924 // R-values and const R-values supported here with zero runtime overhead
925 ///////////////////////////////////////////////////////////////////////////////
926
927 // No variable is needed to track the rvalue-ness of the collection expression
928 # define BOOST_FOREACH_PREAMBLE()                                                               \
929     BOOST_FOREACH_SUPPRESS_WARNINGS()
930
931 // Evaluate the collection expression
932 # define BOOST_FOREACH_EVALUATE(COL)                                                            \
933     (COL)
934
935 # define BOOST_FOREACH_SHOULD_COPY(COL)                                                         \
936     (true ? 0 : boost::foreach_detail_::or_(                                                    \
937         BOOST_FOREACH_IS_RVALUE(COL)                                                            \
938       , BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(COL)))
939
940 #elif defined(BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION)
941 ///////////////////////////////////////////////////////////////////////////////
942 // R-values and const R-values supported here
943 ///////////////////////////////////////////////////////////////////////////////
944
945 // Declare a variable to track the rvalue-ness of the collection expression
946 # define BOOST_FOREACH_PREAMBLE()                                                               \
947     BOOST_FOREACH_SUPPRESS_WARNINGS()                                                           \
948     if (bool BOOST_FOREACH_ID(_foreach_is_rvalue) = false) {} else
949
950 // Evaluate the collection expression, and detect if it is an lvalue or and rvalue
951 # define BOOST_FOREACH_EVALUATE(COL)                                                            \
952     (true ? boost::foreach_detail_::make_probe((COL), BOOST_FOREACH_ID(_foreach_is_rvalue)) : (COL))
953
954 // The rvalue/lvalue-ness of the collection expression is determined dynamically, unless
955 // the type is an array or is noncopyable or is non-const, in which case we know it's an lvalue.
956 // If the type happens to be a lightweight proxy, always make a copy.
957 # define BOOST_FOREACH_SHOULD_COPY(COL)                                                         \
958     (boost::foreach_detail_::should_copy_impl(                                                  \
959         true ? 0 : boost::foreach_detail_::or_(                                                 \
960             boost::foreach_detail_::is_array_(COL)                                              \
961           , BOOST_FOREACH_IS_NONCOPYABLE(COL)                                                   \
962           , boost::foreach_detail_::not_(boost::foreach_detail_::is_const_(COL)))               \
963       , true ? 0 : BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(COL)                                      \
964       , &BOOST_FOREACH_ID(_foreach_is_rvalue)))
965
966 #elif !defined(BOOST_FOREACH_NO_RVALUE_DETECTION)
967 ///////////////////////////////////////////////////////////////////////////////
968 // R-values supported here, const R-values NOT supported here
969 ///////////////////////////////////////////////////////////////////////////////
970
971 // No variable is needed to track the rvalue-ness of the collection expression
972 # define BOOST_FOREACH_PREAMBLE()                                                               \
973     BOOST_FOREACH_SUPPRESS_WARNINGS()
974
975 // Evaluate the collection expression
976 # define BOOST_FOREACH_EVALUATE(COL)                                                            \
977     (COL)
978
979 // Determine whether the collection expression is an lvalue or an rvalue.
980 // NOTE: this gets the answer wrong for const rvalues.
981 # define BOOST_FOREACH_SHOULD_COPY(COL)                                                         \
982     (true ? 0 : boost::foreach_detail_::or_(                                                    \
983         boost::foreach_detail_::is_rvalue_((COL), 0)                                            \
984       , BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(COL)))
985
986 #else
987 ///////////////////////////////////////////////////////////////////////////////
988 // R-values NOT supported here
989 ///////////////////////////////////////////////////////////////////////////////
990
991 // No variable is needed to track the rvalue-ness of the collection expression
992 # define BOOST_FOREACH_PREAMBLE()                                                               \
993     BOOST_FOREACH_SUPPRESS_WARNINGS()
994
995 // Evaluate the collection expression
996 # define BOOST_FOREACH_EVALUATE(COL)                                                            \
997     (COL)
998
999 // Can't use rvalues with BOOST_FOREACH (unless they are lightweight proxies)
1000 # define BOOST_FOREACH_SHOULD_COPY(COL)                                                         \
1001     (true ? 0 : BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(COL))
1002
1003 #endif
1004
1005 #define BOOST_FOREACH_CONTAIN(COL)                                                              \
1006     boost::foreach_detail_::contain(                                                            \
1007         BOOST_FOREACH_EVALUATE(COL)                                                             \
1008       , BOOST_FOREACH_SHOULD_COPY(COL))
1009
1010 #define BOOST_FOREACH_BEGIN(COL)                                                                \
1011     boost::foreach_detail_::begin(                                                              \
1012         BOOST_FOREACH_ID(_foreach_col)                                                          \
1013       , BOOST_FOREACH_TYPEOF(COL)                                                               \
1014       , BOOST_FOREACH_SHOULD_COPY(COL))
1015
1016 #define BOOST_FOREACH_END(COL)                                                                  \
1017     boost::foreach_detail_::end(                                                                \
1018         BOOST_FOREACH_ID(_foreach_col)                                                          \
1019       , BOOST_FOREACH_TYPEOF(COL)                                                               \
1020       , BOOST_FOREACH_SHOULD_COPY(COL))
1021
1022 #define BOOST_FOREACH_DONE(COL)                                                                 \
1023     boost::foreach_detail_::done(                                                               \
1024         BOOST_FOREACH_ID(_foreach_cur)                                                          \
1025       , BOOST_FOREACH_ID(_foreach_end)                                                          \
1026       , BOOST_FOREACH_TYPEOF(COL))
1027
1028 #define BOOST_FOREACH_NEXT(COL)                                                                 \
1029     boost::foreach_detail_::next(                                                               \
1030         BOOST_FOREACH_ID(_foreach_cur)                                                          \
1031       , BOOST_FOREACH_TYPEOF(COL))
1032
1033 #define BOOST_FOREACH_DEREF(COL)                                                                \
1034     boost::foreach_detail_::deref(                                                              \
1035         BOOST_FOREACH_ID(_foreach_cur)                                                          \
1036       , BOOST_FOREACH_TYPEOF(COL))
1037
1038 #define BOOST_FOREACH_RBEGIN(COL)                                                               \
1039     boost::foreach_detail_::rbegin(                                                             \
1040         BOOST_FOREACH_ID(_foreach_col)                                                          \
1041       , BOOST_FOREACH_TYPEOF(COL)                                                               \
1042       , BOOST_FOREACH_SHOULD_COPY(COL))
1043
1044 #define BOOST_FOREACH_REND(COL)                                                                 \
1045     boost::foreach_detail_::rend(                                                               \
1046         BOOST_FOREACH_ID(_foreach_col)                                                          \
1047       , BOOST_FOREACH_TYPEOF(COL)                                                               \
1048       , BOOST_FOREACH_SHOULD_COPY(COL))
1049
1050 #define BOOST_FOREACH_RDONE(COL)                                                                \
1051     boost::foreach_detail_::rdone(                                                              \
1052         BOOST_FOREACH_ID(_foreach_cur)                                                          \
1053       , BOOST_FOREACH_ID(_foreach_end)                                                          \
1054       , BOOST_FOREACH_TYPEOF(COL))
1055
1056 #define BOOST_FOREACH_RNEXT(COL)                                                                \
1057     boost::foreach_detail_::rnext(                                                              \
1058         BOOST_FOREACH_ID(_foreach_cur)                                                          \
1059       , BOOST_FOREACH_TYPEOF(COL))
1060
1061 #define BOOST_FOREACH_RDEREF(COL)                                                               \
1062     boost::foreach_detail_::rderef(                                                             \
1063         BOOST_FOREACH_ID(_foreach_cur)                                                          \
1064       , BOOST_FOREACH_TYPEOF(COL))
1065
1066 ///////////////////////////////////////////////////////////////////////////////
1067 // BOOST_FOREACH
1068 //
1069 //   For iterating over collections. Collections can be
1070 //   arrays, null-terminated strings, or STL containers.
1071 //   The loop variable can be a value or reference. For
1072 //   example:
1073 //
1074 //   std::list<int> int_list(/*stuff*/);
1075 //   BOOST_FOREACH(int &i, int_list)
1076 //   {
1077 //       /* 
1078 //        * loop body goes here.
1079 //        * i is a reference to the int in int_list.
1080 //        */
1081 //   }
1082 //
1083 //   Alternately, you can declare the loop variable first,
1084 //   so you can access it after the loop finishes. Obviously,
1085 //   if you do it this way, then the loop variable cannot be
1086 //   a reference.
1087 //
1088 //   int i;
1089 //   BOOST_FOREACH(i, int_list)
1090 //       { ... }
1091 //
1092 #define BOOST_FOREACH(VAR, COL)                                                                                   \
1093     BOOST_FOREACH_PREAMBLE()                                                                                      \
1094     if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_col) = BOOST_FOREACH_CONTAIN(COL)) {} else   \
1095     if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_cur) = BOOST_FOREACH_BEGIN(COL)) {} else     \
1096     if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_end) = BOOST_FOREACH_END(COL)) {} else       \
1097     for (bool BOOST_FOREACH_ID(_foreach_continue) = true;                                                         \
1098               BOOST_FOREACH_ID(_foreach_continue) && !BOOST_FOREACH_DONE(COL);                                    \
1099               BOOST_FOREACH_ID(_foreach_continue) ? BOOST_FOREACH_NEXT(COL) : (void)0)                            \
1100         if  (boost::foreach_detail_::set_false(BOOST_FOREACH_ID(_foreach_continue))) {} else                      \
1101         for (VAR = BOOST_FOREACH_DEREF(COL); !BOOST_FOREACH_ID(_foreach_continue); BOOST_FOREACH_ID(_foreach_continue) = true)
1102
1103 ///////////////////////////////////////////////////////////////////////////////
1104 // BOOST_REVERSE_FOREACH
1105 //
1106 //   For iterating over collections in reverse order. In
1107 //   all other respects, BOOST_REVERSE_FOREACH is like
1108 //   BOOST_FOREACH.
1109 //
1110 #define BOOST_REVERSE_FOREACH(VAR, COL)                                                                           \
1111     BOOST_FOREACH_PREAMBLE()                                                                                      \
1112     if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_col) = BOOST_FOREACH_CONTAIN(COL)) {} else   \
1113     if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_cur) = BOOST_FOREACH_RBEGIN(COL)) {} else    \
1114     if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_end) = BOOST_FOREACH_REND(COL)) {} else      \
1115     for (bool BOOST_FOREACH_ID(_foreach_continue) = true;                                                         \
1116               BOOST_FOREACH_ID(_foreach_continue) && !BOOST_FOREACH_RDONE(COL);                                   \
1117               BOOST_FOREACH_ID(_foreach_continue) ? BOOST_FOREACH_RNEXT(COL) : (void)0)                           \
1118         if  (boost::foreach_detail_::set_false(BOOST_FOREACH_ID(_foreach_continue))) {} else                      \
1119         for (VAR = BOOST_FOREACH_RDEREF(COL); !BOOST_FOREACH_ID(_foreach_continue); BOOST_FOREACH_ID(_foreach_continue) = true)
1120
1121 #endif