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