Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/foreach.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // foreach.hpp header file
0003 //
0004 // Copyright 2004 Eric Niebler.
0005 // Distributed under the Boost Software License, Version 1.0. (See
0006 // accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt)
0008 // See http://www.boost.org/libs/foreach for documentation
0009 //
0010 // Credits:
0011 //  Anson Tsao        - for the initial inspiration and several good suggestions.
0012 //  Thorsten Ottosen  - for Boost.Range, and for suggesting a way to detect
0013 //                      const-qualified rvalues at compile time on VC7.1+
0014 //  Russell Hind      - For help porting to Borland
0015 //  Alisdair Meredith - For help porting to Borland
0016 //  Stefan Slapeta    - For help porting to Intel
0017 //  David Jenkins     - For help finding a Microsoft Code Analysis bug
0018 //  mimomorin@...     - For a patch to use rvalue refs on supporting compilers
0019 
0020 #ifndef BOOST_FOREACH
0021 
0022 // MS compatible compilers support #pragma once
0023 #if defined(_MSC_VER)
0024 # pragma once
0025 #endif
0026 
0027 #include <cstddef>
0028 #include <utility>  // for std::pair
0029 
0030 #include <boost/config.hpp>
0031 #include <boost/detail/workaround.hpp>
0032 
0033 // Define a compiler generic null pointer value
0034 #if defined(BOOST_NO_NULLPTR)
0035 #define BOOST_FOREACH_NULL 0
0036 #else
0037 #define BOOST_FOREACH_NULL nullptr
0038 #endif
0039 
0040 // Some compilers let us detect even const-qualified rvalues at compile-time
0041 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)                                                   \
0042  || defined(BOOST_MSVC) && !defined(_PREFAST_)                                 \
0043  || (BOOST_WORKAROUND(__GNUC__, == 4) && (__GNUC_MINOR__ <= 5) && !defined(BOOST_INTEL) &&       \
0044                                                                   !defined(BOOST_CLANG))         \
0045  || (BOOST_WORKAROUND(__GNUC__, == 3) && (__GNUC_MINOR__ >= 4) && !defined(BOOST_INTEL) &&       \
0046                                                                   !defined(BOOST_CLANG))
0047 # define BOOST_FOREACH_COMPILE_TIME_CONST_RVALUE_DETECTION
0048 #else
0049 // Some compilers allow temporaries to be bound to non-const references.
0050 // These compilers make it impossible to for BOOST_FOREACH to detect
0051 // temporaries and avoid reevaluation of the collection expression.
0052 # if BOOST_WORKAROUND(BOOST_BORLANDC, < 0x593)                                                    \
0053   || (BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 700) && defined(_MSC_VER))                   \
0054   || BOOST_WORKAROUND(__SUNPRO_CC, < 0x5100)                                                    \
0055   || BOOST_WORKAROUND(__DECCXX_VER, <= 60590042)
0056 #  define BOOST_FOREACH_NO_RVALUE_DETECTION
0057 # endif
0058 // Some compilers do not correctly implement the lvalue/rvalue conversion
0059 // rules of the ternary conditional operator.
0060 # if defined(BOOST_FOREACH_NO_RVALUE_DETECTION)                                                 \
0061   || defined(BOOST_NO_SFINAE)                                                                   \
0062   || BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1400))                                        \
0063   || BOOST_WORKAROUND(BOOST_INTEL_WIN, BOOST_TESTED_AT(1400))                                   \
0064   || (BOOST_WORKAROUND(__GNUC__, == 3) && (__GNUC_MINOR__ <= 3) && defined(__APPLE_CC__))       \
0065   || BOOST_WORKAROUND(__IBMCPP__, BOOST_TESTED_AT(600))                                         \
0066   || BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206))                                      \
0067   || BOOST_WORKAROUND(__SUNPRO_CC, >= 0x5100)                                                   \
0068   || BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x590))
0069 #  define BOOST_FOREACH_NO_CONST_RVALUE_DETECTION
0070 # else
0071 #  define BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION
0072 # endif
0073 #endif
0074 
0075 #include <boost/mpl/if.hpp>
0076 #include <boost/mpl/assert.hpp>
0077 #include <boost/mpl/logical.hpp>
0078 #include <boost/mpl/eval_if.hpp>
0079 #include <boost/noncopyable.hpp>
0080 #include <boost/range/end.hpp>
0081 #include <boost/range/begin.hpp>
0082 #include <boost/range/rend.hpp>
0083 #include <boost/range/rbegin.hpp>
0084 #include <boost/range/iterator.hpp>
0085 #include <boost/range/reverse_iterator.hpp>
0086 #include <boost/type_traits/is_array.hpp>
0087 #include <boost/type_traits/is_const.hpp>
0088 #include <boost/type_traits/is_abstract.hpp>
0089 #include <boost/type_traits/is_base_and_derived.hpp>
0090 #include <boost/type_traits/is_rvalue_reference.hpp>
0091 #include <boost/type_traits/is_convertible.hpp>
0092 #include <boost/iterator/iterator_traits.hpp>
0093 #include <boost/utility/addressof.hpp>
0094 #include <boost/foreach_fwd.hpp>
0095 
0096 #ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION
0097 # include <new>
0098 # include <boost/aligned_storage.hpp>
0099 # include <boost/utility/enable_if.hpp>
0100 # include <boost/type_traits/remove_const.hpp>
0101 #endif
0102 
0103 namespace boost
0104 {
0105 
0106 // forward declarations for iterator_range
0107 template<typename T>
0108 class iterator_range;
0109 
0110 // forward declarations for sub_range
0111 template<typename T>
0112 class sub_range;
0113 
0114 namespace foreach
0115 {
0116     ///////////////////////////////////////////////////////////////////////////////
0117     // in_range
0118     //
0119     template<typename T>
0120     inline std::pair<T, T> in_range(T begin, T end)
0121     {
0122         return std::make_pair(begin, end);
0123     }
0124 
0125     ///////////////////////////////////////////////////////////////////////////////
0126     // boost::foreach::is_lightweight_proxy
0127     //   Specialize this for user-defined collection types if they are inexpensive to copy.
0128     //   This tells BOOST_FOREACH it can avoid the rvalue/lvalue detection stuff.
0129     template<typename T>
0130     struct is_lightweight_proxy
0131       : boost::mpl::false_
0132     {
0133     };
0134 
0135     ///////////////////////////////////////////////////////////////////////////////
0136     // boost::foreach::is_noncopyable
0137     //   Specialize this for user-defined collection types if they cannot be copied.
0138     //   This also tells BOOST_FOREACH to avoid the rvalue/lvalue detection stuff.
0139     template<typename T>
0140     struct is_noncopyable
0141     #if !defined(BOOST_BROKEN_IS_BASE_AND_DERIVED) && !defined(BOOST_NO_IS_ABSTRACT)
0142       : boost::mpl::or_<
0143             boost::is_abstract<T>
0144           , boost::is_base_and_derived<boost::noncopyable, T>
0145         >
0146     #elif !defined(BOOST_BROKEN_IS_BASE_AND_DERIVED)
0147       : boost::is_base_and_derived<boost::noncopyable, T>
0148     #elif !defined(BOOST_NO_IS_ABSTRACT)
0149       : boost::is_abstract<T>
0150     #else
0151       : boost::mpl::false_
0152     #endif
0153     {
0154     };
0155 
0156 } // namespace foreach
0157 
0158 } // namespace boost
0159 
0160 // vc6/7 needs help ordering the following overloads
0161 #ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
0162 # define BOOST_FOREACH_TAG_DEFAULT ...
0163 #else
0164 # define BOOST_FOREACH_TAG_DEFAULT boost::foreach::tag
0165 #endif
0166 
0167 ///////////////////////////////////////////////////////////////////////////////
0168 // boost_foreach_is_lightweight_proxy
0169 //   Another customization point for the is_lightweight_proxy optimization,
0170 //   this one works on legacy compilers. Overload boost_foreach_is_lightweight_proxy
0171 //   at the global namespace for your type.
0172 template<typename T>
0173 inline boost::foreach::is_lightweight_proxy<T> *
0174 boost_foreach_is_lightweight_proxy(T *&, BOOST_FOREACH_TAG_DEFAULT) { return 0; }
0175 
0176 template<typename T>
0177 inline boost::mpl::true_ *
0178 boost_foreach_is_lightweight_proxy(std::pair<T, T> *&, boost::foreach::tag) { return 0; }
0179 
0180 template<typename T>
0181 inline boost::mpl::true_ *
0182 boost_foreach_is_lightweight_proxy(boost::iterator_range<T> *&, boost::foreach::tag) { return 0; }
0183 
0184 template<typename T>
0185 inline boost::mpl::true_ *
0186 boost_foreach_is_lightweight_proxy(boost::sub_range<T> *&, boost::foreach::tag) { return 0; }
0187 
0188 template<typename T>
0189 inline boost::mpl::true_ *
0190 boost_foreach_is_lightweight_proxy(T **&, boost::foreach::tag) { return 0; }
0191 
0192 ///////////////////////////////////////////////////////////////////////////////
0193 // boost_foreach_is_noncopyable
0194 //   Another customization point for the is_noncopyable trait,
0195 //   this one works on legacy compilers. Overload boost_foreach_is_noncopyable
0196 //   at the global namespace for your type.
0197 template<typename T>
0198 inline boost::foreach::is_noncopyable<T> *
0199 boost_foreach_is_noncopyable(T *&, BOOST_FOREACH_TAG_DEFAULT) { return 0; }
0200 
0201 namespace boost
0202 {
0203 
0204 namespace foreach_detail_
0205 {
0206 
0207 ///////////////////////////////////////////////////////////////////////////////
0208 // Define some utilities for assessing the properties of expressions
0209 //
0210 template<typename Bool1, typename Bool2>
0211 inline boost::mpl::and_<Bool1, Bool2> *and_(Bool1 *, Bool2 *) { return 0; }
0212 
0213 template<typename Bool1, typename Bool2, typename Bool3>
0214 inline boost::mpl::and_<Bool1, Bool2, Bool3> *and_(Bool1 *, Bool2 *, Bool3 *) { return 0; }
0215 
0216 template<typename Bool1, typename Bool2>
0217 inline boost::mpl::or_<Bool1, Bool2> *or_(Bool1 *, Bool2 *) { return 0; }
0218 
0219 template<typename Bool1, typename Bool2, typename Bool3>
0220 inline boost::mpl::or_<Bool1, Bool2, Bool3> *or_(Bool1 *, Bool2 *, Bool3 *) { return 0; }
0221 
0222 template<typename Bool1>
0223 inline boost::mpl::not_<Bool1> *not_(Bool1 *) { return 0; }
0224 
0225 template<typename T>
0226 inline boost::is_array<T> *is_array_(T const &) { return 0; }
0227 
0228 template<typename T>
0229 inline boost::is_const<T> *is_const_(T &) { return 0; }
0230 
0231 #ifndef BOOST_FOREACH_NO_RVALUE_DETECTION
0232 template<typename T>
0233 inline boost::mpl::true_ *is_const_(T const &) { return 0; }
0234 #endif
0235 
0236 #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
0237 template<typename T>
0238 inline boost::mpl::false_ *is_rvalue_(T &, int) { return 0; }
0239 
0240 template<typename T>
0241 inline boost::mpl::true_ *is_rvalue_(T const &, ...) { return 0; }
0242 #else
0243 template<typename T>
0244 inline boost::is_rvalue_reference<T &&> *is_rvalue_(T &&, int) { return 0; }
0245 #endif
0246 
0247 ///////////////////////////////////////////////////////////////////////////////
0248 // auto_any_t/auto_any
0249 //  General utility for putting an object of any type into automatic storage
0250 struct auto_any_base
0251 {
0252     // auto_any_base must evaluate to false in boolean context so that
0253     // they can be declared in if() statements.
0254     operator bool() const
0255     {
0256         return false;
0257     }
0258 };
0259 
0260 template<typename T>
0261 struct auto_any : auto_any_base
0262 {
0263     explicit auto_any(T const &t)
0264       : item(t)
0265     {
0266     }
0267 
0268     // temporaries of type auto_any will be bound to const auto_any_base
0269     // references, but we still want to be able to mutate the stored
0270     // data, so declare it as mutable.
0271     mutable T item;
0272 };
0273 
0274 typedef auto_any_base const &auto_any_t;
0275 
0276 template<typename T, typename C>
0277 inline BOOST_DEDUCED_TYPENAME boost::mpl::if_<C, T const, T>::type &auto_any_cast(auto_any_t a)
0278 {
0279     return static_cast<auto_any<T> const &>(a).item;
0280 }
0281 
0282 typedef boost::mpl::true_ const_;
0283 
0284 ///////////////////////////////////////////////////////////////////////////////
0285 // type2type
0286 //
0287 template<typename T, typename C = boost::mpl::false_>
0288 struct type2type
0289   : boost::mpl::if_<C, T const, T>
0290 {
0291 };
0292 
0293 template<typename T>
0294 struct wrap_cstr
0295 {
0296     typedef T type;
0297 };
0298 
0299 template<>
0300 struct wrap_cstr<char *>
0301 {
0302     typedef wrap_cstr<char *> type;
0303     typedef char *iterator;
0304     typedef char *const_iterator;
0305 };
0306 
0307 template<>
0308 struct wrap_cstr<char const *>
0309 {
0310     typedef wrap_cstr<char const *> type;
0311     typedef char const *iterator;
0312     typedef char const *const_iterator;
0313 };
0314 
0315 template<>
0316 struct wrap_cstr<wchar_t *>
0317 {
0318     typedef wrap_cstr<wchar_t *> type;
0319     typedef wchar_t *iterator;
0320     typedef wchar_t *const_iterator;
0321 };
0322 
0323 template<>
0324 struct wrap_cstr<wchar_t const *>
0325 {
0326     typedef wrap_cstr<wchar_t const *> type;
0327     typedef wchar_t const *iterator;
0328     typedef wchar_t const *const_iterator;
0329 };
0330 
0331 template<typename T>
0332 struct is_char_array
0333   : mpl::and_<
0334         is_array<T>
0335       , mpl::or_<
0336             is_convertible<T, char const *>
0337           , is_convertible<T, wchar_t const *>
0338         >
0339     >
0340 {};
0341 
0342 template<typename T, typename C = boost::mpl::false_>
0343 struct foreach_iterator
0344 {
0345     // **** READ THIS IF YOUR COMPILE BREAKS HERE ****
0346     //
0347     // There is an ambiguity about how to iterate over arrays of char and wchar_t. 
0348     // Should the last array element be treated as a null terminator to be skipped, or
0349     // is it just like any other element in the array? To fix the problem, you must
0350     // say which behavior you want.
0351     //
0352     // To treat the container as a null-terminated string, merely cast it to a
0353     // char const *, as in BOOST_FOREACH( char ch, (char const *)"hello" ) ...
0354     //
0355     // To treat the container as an array, use boost::as_array() in <boost/range/as_array.hpp>,
0356     // as in BOOST_FOREACH( char ch, boost::as_array("hello") ) ...
0357     BOOST_MPL_ASSERT_MSG( (!is_char_array<T>::value), IS_THIS_AN_ARRAY_OR_A_NULL_TERMINATED_STRING, (T&) );
0358 
0359     // If the type is a pointer to a null terminated string (as opposed 
0360     // to an array type), there is no ambiguity.
0361     typedef BOOST_DEDUCED_TYPENAME wrap_cstr<T>::type container;
0362 
0363     typedef BOOST_DEDUCED_TYPENAME boost::mpl::eval_if<
0364         C
0365       , range_const_iterator<container>
0366       , range_mutable_iterator<container>
0367     >::type type;
0368 };
0369 
0370 
0371 template<typename T, typename C = boost::mpl::false_>
0372 struct foreach_reverse_iterator
0373 {
0374     // **** READ THIS IF YOUR COMPILE BREAKS HERE ****
0375     //
0376     // There is an ambiguity about how to iterate over arrays of char and wchar_t. 
0377     // Should the last array element be treated as a null terminator to be skipped, or
0378     // is it just like any other element in the array? To fix the problem, you must
0379     // say which behavior you want.
0380     //
0381     // To treat the container as a null-terminated string, merely cast it to a
0382     // char const *, as in BOOST_FOREACH( char ch, (char const *)"hello" ) ...
0383     //
0384     // To treat the container as an array, use boost::as_array() in <boost/range/as_array.hpp>,
0385     // as in BOOST_FOREACH( char ch, boost::as_array("hello") ) ...
0386     BOOST_MPL_ASSERT_MSG( (!is_char_array<T>::value), IS_THIS_AN_ARRAY_OR_A_NULL_TERMINATED_STRING, (T&) );
0387 
0388     // If the type is a pointer to a null terminated string (as opposed 
0389     // to an array type), there is no ambiguity.
0390     typedef BOOST_DEDUCED_TYPENAME wrap_cstr<T>::type container;
0391 
0392     typedef BOOST_DEDUCED_TYPENAME boost::mpl::eval_if<
0393         C
0394       , range_reverse_iterator<container const>
0395       , range_reverse_iterator<container>
0396     >::type type;
0397 };
0398 
0399 template<typename T, typename C = boost::mpl::false_>
0400 struct foreach_reference
0401   : iterator_reference<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>
0402 {
0403 };
0404 
0405 ///////////////////////////////////////////////////////////////////////////////
0406 // encode_type
0407 //
0408 template<typename T>
0409 inline type2type<T> *encode_type(T &, boost::false_type*) { return 0; }
0410 
0411 template<typename T>
0412 inline type2type<T, const_> *encode_type(T const &, boost::true_type*) { return 0; }
0413 
0414 template<typename T>
0415 inline type2type<T> *encode_type(T &, boost::mpl::false_*) { return 0; }
0416 
0417 template<typename T>
0418 inline type2type<T, const_> *encode_type(T const &, boost::mpl::true_*) { return 0; }
0419 
0420 ///////////////////////////////////////////////////////////////////////////////
0421 // set_false
0422 //
0423 inline bool set_false(bool &b)
0424 {
0425     b = false;
0426     return false;
0427 }
0428 
0429 ///////////////////////////////////////////////////////////////////////////////
0430 // to_ptr
0431 //
0432 template<typename T>
0433 inline T *&to_ptr(T const &)
0434 {
0435     static T *t = 0;
0436     return t;
0437 }
0438 
0439 // Borland needs a little extra help with arrays
0440 #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
0441 template<typename T,std::size_t N>
0442 inline T (*&to_ptr(T (&)[N]))[N]
0443 {
0444     static T (*t)[N] = 0;
0445     return t;
0446 }
0447 
0448 ///////////////////////////////////////////////////////////////////////////////
0449 // derefof
0450 //
0451 template<typename T>
0452 inline T &derefof(T *t)
0453 {
0454     // This is a work-around for a compiler bug in Borland. If T* is a pointer to array type U(*)[N],
0455     // then dereferencing it results in a U* instead of U(&)[N]. The cast forces the issue.
0456     return reinterpret_cast<T &>(
0457         *const_cast<char *>(
0458             reinterpret_cast<char const volatile *>(t)
0459         )
0460     );
0461 }
0462 
0463 # define BOOST_FOREACH_DEREFOF(T) boost::foreach_detail_::derefof(*T)
0464 #else
0465 # define BOOST_FOREACH_DEREFOF(T) (*T)
0466 #endif
0467 
0468 #if defined(BOOST_FOREACH_COMPILE_TIME_CONST_RVALUE_DETECTION)                                  \
0469  && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0470 ///////////////////////////////////////////////////////////////////////////////
0471 // Rvalue references makes it drop-dead simple to detect at compile time
0472 // whether an expression is an rvalue.
0473 ///////////////////////////////////////////////////////////////////////////////
0474 
0475 # define BOOST_FOREACH_IS_RVALUE(COL)                                                           \
0476     boost::foreach_detail_::is_rvalue_((COL), 0)
0477 
0478 #elif defined(BOOST_FOREACH_COMPILE_TIME_CONST_RVALUE_DETECTION)                                \
0479  && defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0480 ///////////////////////////////////////////////////////////////////////////////
0481 // Detect at compile-time whether an expression yields an rvalue or
0482 // an lvalue. This is rather non-standard, but some popular compilers
0483 // accept it.
0484 ///////////////////////////////////////////////////////////////////////////////
0485 
0486 ///////////////////////////////////////////////////////////////////////////////
0487 // rvalue_probe
0488 //
0489 template<typename T>
0490 struct rvalue_probe
0491 {
0492     struct private_type_ {};
0493     // can't ever return an array by value
0494     typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_<
0495         boost::mpl::or_<boost::is_abstract<T>, boost::is_array<T> >, private_type_, T
0496     >::type value_type;
0497     operator value_type() { return *reinterpret_cast<value_type *>(this); } // never called
0498     operator T &() const { return *reinterpret_cast<T *>(const_cast<rvalue_probe *>(this)); } // never called
0499 };
0500 
0501 template<typename T>
0502 rvalue_probe<T> const make_probe(T const &)
0503 {
0504     return rvalue_probe<T>();
0505 }
0506 
0507 # define BOOST_FOREACH_IS_RVALUE(COL)                                                           \
0508     boost::foreach_detail_::and_(                                                               \
0509         boost::foreach_detail_::not_(boost::foreach_detail_::is_array_(COL))                    \
0510       , (true ? 0 : boost::foreach_detail_::is_rvalue_(                                         \
0511             (true ? boost::foreach_detail_::make_probe(COL) : (COL)), 0)))
0512 
0513 #elif defined(BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION)
0514 ///////////////////////////////////////////////////////////////////////////////
0515 // Detect at run-time whether an expression yields an rvalue
0516 // or an lvalue. This is 100% standard C++, but not all compilers
0517 // accept it. Also, it causes FOREACH to break when used with non-
0518 // copyable collection types.
0519 ///////////////////////////////////////////////////////////////////////////////
0520 
0521 ///////////////////////////////////////////////////////////////////////////////
0522 // rvalue_probe
0523 //
0524 template<typename T>
0525 struct rvalue_probe
0526 {
0527     rvalue_probe(T &t, bool &b)
0528       : value(t)
0529       , is_rvalue(b)
0530     {
0531     }
0532 
0533     struct private_type_ {};
0534     // can't ever return an array or an abstract type by value
0535     #ifdef BOOST_NO_IS_ABSTRACT
0536     typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_<
0537         boost::is_array<T>, private_type_, T
0538     >::type value_type;
0539     #else
0540     typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_<
0541         boost::mpl::or_<boost::is_abstract<T>, boost::is_array<T> >, private_type_, T
0542     >::type value_type;
0543     #endif
0544     
0545     operator value_type()
0546     {
0547         this->is_rvalue = true;
0548         return this->value;
0549     }
0550 
0551     operator T &() const
0552     {
0553         return this->value;
0554     }
0555 
0556 private:
0557     T &value;
0558     bool &is_rvalue;
0559 };
0560 
0561 template<typename T>
0562 rvalue_probe<T> make_probe(T &t, bool &b) { return rvalue_probe<T>(t, b); }
0563 
0564 template<typename T>
0565 rvalue_probe<T const> make_probe(T const &t, bool &b)  { return rvalue_probe<T const>(t, b); }
0566 
0567 ///////////////////////////////////////////////////////////////////////////////
0568 // simple_variant
0569 //  holds either a T or a T const*
0570 template<typename T>
0571 struct simple_variant
0572 {
0573     simple_variant(T const *t)
0574       : is_rvalue(false)
0575     {
0576         *static_cast<T const **>(this->data.address()) = t;
0577     }
0578 
0579     simple_variant(T const &t)
0580       : is_rvalue(true)
0581     {
0582         ::new(this->data.address()) T(t);
0583     }
0584 
0585     simple_variant(simple_variant const &that)
0586       : is_rvalue(that.is_rvalue)
0587     {
0588         if(this->is_rvalue)
0589             ::new(this->data.address()) T(*that.get());
0590         else
0591             *static_cast<T const **>(this->data.address()) = that.get();
0592     }
0593 
0594     ~simple_variant()
0595     {
0596         if(this->is_rvalue)
0597             this->get()->~T();
0598     }
0599 
0600     T const *get() const
0601     {
0602         if(this->is_rvalue)
0603             return static_cast<T const *>(this->data.address());
0604         else
0605             return *static_cast<T const * const *>(this->data.address());
0606     }
0607 
0608 private:
0609     enum size_type { size = sizeof(T) > sizeof(T*) ? sizeof(T) : sizeof(T*) };
0610     simple_variant &operator =(simple_variant const &); 
0611     bool const is_rvalue;
0612     aligned_storage<size> data;
0613 };
0614 
0615 // If the collection is an array or is noncopyable, it must be an lvalue.
0616 // If the collection is a lightweight proxy, treat it as an rvalue
0617 // BUGBUG what about a noncopyable proxy?
0618 template<typename LValue, typename IsProxy>
0619 inline BOOST_DEDUCED_TYPENAME boost::enable_if<boost::mpl::or_<LValue, IsProxy>, IsProxy>::type *
0620 should_copy_impl(LValue *, IsProxy *, bool *)
0621 {
0622     return 0;
0623 }
0624 
0625 // Otherwise, we must determine at runtime whether it's an lvalue or rvalue
0626 inline bool *
0627 should_copy_impl(boost::mpl::false_ *, boost::mpl::false_ *, bool *is_rvalue)
0628 {
0629     return is_rvalue;
0630 }
0631 
0632 #endif
0633 
0634 ///////////////////////////////////////////////////////////////////////////////
0635 // contain
0636 //
0637 template<typename T>
0638 inline auto_any<T> contain(T const &t, boost::mpl::true_ *) // rvalue
0639 {
0640     return auto_any<T>(t);
0641 }
0642 
0643 template<typename T>
0644 inline auto_any<T *> contain(T &t, boost::mpl::false_ *) // lvalue
0645 {
0646     // Cannot seem to get sunpro to handle addressof() with array types.
0647     #if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x570))
0648     return auto_any<T *>(&t);
0649     #else
0650     return auto_any<T *>(boost::addressof(t));
0651     #endif
0652 }
0653 
0654 #ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION
0655 template<typename T>
0656 inline auto_any<simple_variant<T> >
0657 contain(T const &t, bool *rvalue)
0658 {
0659     return auto_any<simple_variant<T> >(*rvalue ? simple_variant<T>(t) : simple_variant<T>(&t));
0660 }
0661 #endif
0662 
0663 /////////////////////////////////////////////////////////////////////////////
0664 // begin
0665 //
0666 template<typename T, typename C>
0667 inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>
0668 begin(auto_any_t col, type2type<T, C> *, boost::mpl::true_ *) // rvalue
0669 {
0670     return auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>(
0671         boost::begin(auto_any_cast<T, C>(col)));
0672 }
0673 
0674 template<typename T, typename C>
0675 inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>
0676 begin(auto_any_t col, type2type<T, C> *, boost::mpl::false_ *) // lvalue
0677 {
0678     typedef BOOST_DEDUCED_TYPENAME type2type<T, C>::type type;
0679     typedef BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type iterator;
0680     return auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>(
0681         iterator(boost::begin(BOOST_FOREACH_DEREFOF((auto_any_cast<type *, boost::mpl::false_>(col))))));
0682 }
0683 
0684 #ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION
0685 template<typename T>
0686 inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, const_>::type>
0687 begin(auto_any_t col, type2type<T, const_> *, bool *)
0688 {
0689     return auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, const_>::type>(
0690         boost::begin(*auto_any_cast<simple_variant<T>, boost::mpl::false_>(col).get()));
0691 }
0692 #endif
0693 
0694 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
0695 template<typename T, typename C>
0696 inline auto_any<T *>
0697 begin(auto_any_t col, type2type<T *, C> *, boost::mpl::true_ *) // null-terminated C-style strings
0698 {
0699     return auto_any<T *>(auto_any_cast<T *, boost::mpl::false_>(col));
0700 }
0701 #endif
0702 
0703 ///////////////////////////////////////////////////////////////////////////////
0704 // end
0705 //
0706 template<typename T, typename C>
0707 inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>
0708 end(auto_any_t col, type2type<T, C> *, boost::mpl::true_ *) // rvalue
0709 {
0710     return auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>(
0711         boost::end(auto_any_cast<T, C>(col)));
0712 }
0713 
0714 template<typename T, typename C>
0715 inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>
0716 end(auto_any_t col, type2type<T, C> *, boost::mpl::false_ *) // lvalue
0717 {
0718     typedef BOOST_DEDUCED_TYPENAME type2type<T, C>::type type;
0719     typedef BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type iterator;
0720     return auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>(
0721         iterator(boost::end(BOOST_FOREACH_DEREFOF((auto_any_cast<type *, boost::mpl::false_>(col))))));
0722 }
0723 
0724 #ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION
0725 template<typename T>
0726 inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, const_>::type>
0727 end(auto_any_t col, type2type<T, const_> *, bool *)
0728 {
0729     return auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, const_>::type>(
0730         boost::end(*auto_any_cast<simple_variant<T>, boost::mpl::false_>(col).get()));
0731 }
0732 #endif
0733 
0734 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
0735 template<typename T, typename C>
0736 inline auto_any<int>
0737 end(auto_any_t, type2type<T *, C> *, boost::mpl::true_ *) // null-terminated C-style strings
0738 {
0739     return auto_any<int>(0); // not used
0740 }
0741 #endif
0742 
0743 ///////////////////////////////////////////////////////////////////////////////
0744 // done
0745 //
0746 template<typename T, typename C>
0747 inline bool done(auto_any_t cur, auto_any_t end, type2type<T, C> *)
0748 {
0749     typedef BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type iter_t;
0750     return auto_any_cast<iter_t, boost::mpl::false_>(cur) == auto_any_cast<iter_t, boost::mpl::false_>(end);
0751 }
0752 
0753 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
0754 template<typename T, typename C>
0755 inline bool done(auto_any_t cur, auto_any_t, type2type<T *, C> *) // null-terminated C-style strings
0756 {
0757     return ! *auto_any_cast<T *, boost::mpl::false_>(cur);
0758 }
0759 #endif
0760 
0761 ///////////////////////////////////////////////////////////////////////////////
0762 // next
0763 //
0764 template<typename T, typename C>
0765 inline void next(auto_any_t cur, type2type<T, C> *)
0766 {
0767     typedef BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type iter_t;
0768     ++auto_any_cast<iter_t, boost::mpl::false_>(cur);
0769 }
0770 
0771 ///////////////////////////////////////////////////////////////////////////////
0772 // deref
0773 //
0774 template<typename T, typename C>
0775 inline BOOST_DEDUCED_TYPENAME foreach_reference<T, C>::type
0776 deref(auto_any_t cur, type2type<T, C> *)
0777 {
0778     typedef BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type iter_t;
0779     return *auto_any_cast<iter_t, boost::mpl::false_>(cur);
0780 }
0781 
0782 /////////////////////////////////////////////////////////////////////////////
0783 // rbegin
0784 //
0785 template<typename T, typename C>
0786 inline auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type>
0787 rbegin(auto_any_t col, type2type<T, C> *, boost::mpl::true_ *) // rvalue
0788 {
0789     return auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type>(
0790         boost::rbegin(auto_any_cast<T, C>(col)));
0791 }
0792 
0793 template<typename T, typename C>
0794 inline auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type>
0795 rbegin(auto_any_t col, type2type<T, C> *, boost::mpl::false_ *) // lvalue
0796 {
0797     typedef BOOST_DEDUCED_TYPENAME type2type<T, C>::type type;
0798     typedef BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type iterator;
0799     return auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type>(
0800         iterator(boost::rbegin(BOOST_FOREACH_DEREFOF((auto_any_cast<type *, boost::mpl::false_>(col))))));
0801 }
0802 
0803 #ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION
0804 template<typename T>
0805 inline auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, const_>::type>
0806 rbegin(auto_any_t col, type2type<T, const_> *, bool *)
0807 {
0808     return auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, const_>::type>(
0809         boost::rbegin(*auto_any_cast<simple_variant<T>, boost::mpl::false_>(col).get()));
0810 }
0811 #endif
0812 
0813 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
0814 template<typename T, typename C>
0815 inline auto_any<reverse_iterator<T *> >
0816 rbegin(auto_any_t col, type2type<T *, C> *, boost::mpl::true_ *) // null-terminated C-style strings
0817 {
0818     T *p = auto_any_cast<T *, boost::mpl::false_>(col);
0819     while(0 != *p)
0820         ++p;
0821     return auto_any<reverse_iterator<T *> >(reverse_iterator<T *>(p));
0822 }
0823 #endif
0824 
0825 ///////////////////////////////////////////////////////////////////////////////
0826 // rend
0827 //
0828 template<typename T, typename C>
0829 inline auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type>
0830 rend(auto_any_t col, type2type<T, C> *, boost::mpl::true_ *) // rvalue
0831 {
0832     return auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type>(
0833         boost::rend(auto_any_cast<T, C>(col)));
0834 }
0835 
0836 template<typename T, typename C>
0837 inline auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type>
0838 rend(auto_any_t col, type2type<T, C> *, boost::mpl::false_ *) // lvalue
0839 {
0840     typedef BOOST_DEDUCED_TYPENAME type2type<T, C>::type type;
0841     typedef BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type iterator;
0842     return auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type>(
0843         iterator(boost::rend(BOOST_FOREACH_DEREFOF((auto_any_cast<type *, boost::mpl::false_>(col))))));
0844 }
0845 
0846 #ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION
0847 template<typename T>
0848 inline auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, const_>::type>
0849 rend(auto_any_t col, type2type<T, const_> *, bool *)
0850 {
0851     return auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, const_>::type>(
0852         boost::rend(*auto_any_cast<simple_variant<T>, boost::mpl::false_>(col).get()));
0853 }
0854 #endif
0855 
0856 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
0857 template<typename T, typename C>
0858 inline auto_any<reverse_iterator<T *> >
0859 rend(auto_any_t col, type2type<T *, C> *, boost::mpl::true_ *) // null-terminated C-style strings
0860 {
0861     return auto_any<reverse_iterator<T *> >(
0862         reverse_iterator<T *>(auto_any_cast<T *, boost::mpl::false_>(col)));
0863 }
0864 #endif
0865 
0866 ///////////////////////////////////////////////////////////////////////////////
0867 // rdone
0868 //
0869 template<typename T, typename C>
0870 inline bool rdone(auto_any_t cur, auto_any_t end, type2type<T, C> *)
0871 {
0872     typedef BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type iter_t;
0873     return auto_any_cast<iter_t, boost::mpl::false_>(cur) == auto_any_cast<iter_t, boost::mpl::false_>(end);
0874 }
0875 
0876 ///////////////////////////////////////////////////////////////////////////////
0877 // rnext
0878 //
0879 template<typename T, typename C>
0880 inline void rnext(auto_any_t cur, type2type<T, C> *)
0881 {
0882     typedef BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type iter_t;
0883     ++auto_any_cast<iter_t, boost::mpl::false_>(cur);
0884 }
0885 
0886 ///////////////////////////////////////////////////////////////////////////////
0887 // rderef
0888 //
0889 template<typename T, typename C>
0890 inline BOOST_DEDUCED_TYPENAME foreach_reference<T, C>::type
0891 rderef(auto_any_t cur, type2type<T, C> *)
0892 {
0893     typedef BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type iter_t;
0894     return *auto_any_cast<iter_t, boost::mpl::false_>(cur);
0895 }
0896 
0897 } // namespace foreach_detail_
0898 } // namespace boost
0899 
0900 // Suppress a bogus code analysis warning on vc8+
0901 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
0902 # define BOOST_FOREACH_SUPPRESS_WARNINGS() __pragma(warning(suppress:6001))
0903 #else
0904 # define BOOST_FOREACH_SUPPRESS_WARNINGS()
0905 #endif
0906 
0907 ///////////////////////////////////////////////////////////////////////////////
0908 // Define a macro for giving hidden variables a unique name. Not strictly
0909 // needed, but eliminates some warnings on some compilers.
0910 #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
0911 // With some versions of MSVC, use of __LINE__ to create unique identifiers
0912 // can fail when the Edit-and-Continue debug flag is used.
0913 # define BOOST_FOREACH_ID(x) x
0914 #else
0915 # define BOOST_FOREACH_ID(x) BOOST_PP_CAT(x, __LINE__)
0916 #endif
0917 
0918 // A sneaky way to get the type of the collection without evaluating the expression
0919 #define BOOST_FOREACH_TYPEOF(COL)                                                               \
0920     (true ? BOOST_FOREACH_NULL : boost::foreach_detail_::encode_type(COL, boost::foreach_detail_::is_const_(COL)))
0921 
0922 // returns true_* if the type is noncopyable
0923 #define BOOST_FOREACH_IS_NONCOPYABLE(COL)                                                       \
0924     boost_foreach_is_noncopyable(                                                               \
0925         boost::foreach_detail_::to_ptr(COL)                                                     \
0926       , boost_foreach_argument_dependent_lookup_hack_value)
0927 
0928 // returns true_* if the type is a lightweight proxy (and is not noncopyable)
0929 #define BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(COL)                                                 \
0930     boost::foreach_detail_::and_(                                                               \
0931         boost::foreach_detail_::not_(BOOST_FOREACH_IS_NONCOPYABLE(COL))                         \
0932       , boost_foreach_is_lightweight_proxy(                                                     \
0933             boost::foreach_detail_::to_ptr(COL)                                                 \
0934           , boost_foreach_argument_dependent_lookup_hack_value))
0935 
0936 #if defined(BOOST_FOREACH_COMPILE_TIME_CONST_RVALUE_DETECTION)
0937 ///////////////////////////////////////////////////////////////////////////////
0938 // R-values and const R-values supported here with zero runtime overhead
0939 ///////////////////////////////////////////////////////////////////////////////
0940 
0941 // No variable is needed to track the rvalue-ness of the collection expression
0942 # define BOOST_FOREACH_PREAMBLE()                                                               \
0943     BOOST_FOREACH_SUPPRESS_WARNINGS()
0944 
0945 // Evaluate the collection expression
0946 # define BOOST_FOREACH_EVALUATE(COL)                                                            \
0947     (COL)
0948 
0949 # define BOOST_FOREACH_SHOULD_COPY(COL)                                                         \
0950     (true ? BOOST_FOREACH_NULL : boost::foreach_detail_::or_(                                                    \
0951         BOOST_FOREACH_IS_RVALUE(COL)                                                            \
0952       , BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(COL)))
0953 
0954 #elif defined(BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION)
0955 ///////////////////////////////////////////////////////////////////////////////
0956 // R-values and const R-values supported here
0957 ///////////////////////////////////////////////////////////////////////////////
0958 
0959 // Declare a variable to track the rvalue-ness of the collection expression
0960 # define BOOST_FOREACH_PREAMBLE()                                                               \
0961     BOOST_FOREACH_SUPPRESS_WARNINGS()                                                           \
0962     if (bool BOOST_FOREACH_ID(_foreach_is_rvalue) = false) {} else
0963 
0964 // Evaluate the collection expression, and detect if it is an lvalue or and rvalue
0965 # define BOOST_FOREACH_EVALUATE(COL)                                                            \
0966     (true ? boost::foreach_detail_::make_probe((COL), BOOST_FOREACH_ID(_foreach_is_rvalue)) : (COL))
0967 
0968 // The rvalue/lvalue-ness of the collection expression is determined dynamically, unless
0969 // the type is an array or is noncopyable or is non-const, in which case we know it's an lvalue.
0970 // If the type happens to be a lightweight proxy, always make a copy.
0971 # define BOOST_FOREACH_SHOULD_COPY(COL)                                                         \
0972     (boost::foreach_detail_::should_copy_impl(                                                  \
0973         true ? BOOST_FOREACH_NULL : boost::foreach_detail_::or_(                                                 \
0974             boost::foreach_detail_::is_array_(COL)                                              \
0975           , BOOST_FOREACH_IS_NONCOPYABLE(COL)                                                   \
0976           , boost::foreach_detail_::not_(boost::foreach_detail_::is_const_(COL)))               \
0977       , true ? BOOST_FOREACH_NULL : BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(COL)                                      \
0978       , &BOOST_FOREACH_ID(_foreach_is_rvalue)))
0979 
0980 #elif !defined(BOOST_FOREACH_NO_RVALUE_DETECTION)
0981 ///////////////////////////////////////////////////////////////////////////////
0982 // R-values supported here, const R-values NOT supported here
0983 ///////////////////////////////////////////////////////////////////////////////
0984 
0985 // No variable is needed to track the rvalue-ness of the collection expression
0986 # define BOOST_FOREACH_PREAMBLE()                                                               \
0987     BOOST_FOREACH_SUPPRESS_WARNINGS()
0988 
0989 // Evaluate the collection expression
0990 # define BOOST_FOREACH_EVALUATE(COL)                                                            \
0991     (COL)
0992 
0993 // Determine whether the collection expression is an lvalue or an rvalue.
0994 // NOTE: this gets the answer wrong for const rvalues.
0995 # define BOOST_FOREACH_SHOULD_COPY(COL)                                                         \
0996     (true ? BOOST_FOREACH_NULL : boost::foreach_detail_::or_(                                                    \
0997         boost::foreach_detail_::is_rvalue_((COL), 0)                                            \
0998       , BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(COL)))
0999 
1000 #else
1001 ///////////////////////////////////////////////////////////////////////////////
1002 // R-values NOT supported here
1003 ///////////////////////////////////////////////////////////////////////////////
1004 
1005 // No variable is needed to track the rvalue-ness of the collection expression
1006 # define BOOST_FOREACH_PREAMBLE()                                                               \
1007     BOOST_FOREACH_SUPPRESS_WARNINGS()
1008 
1009 // Evaluate the collection expression
1010 # define BOOST_FOREACH_EVALUATE(COL)                                                            \
1011     (COL)
1012 
1013 // Can't use rvalues with BOOST_FOREACH (unless they are lightweight proxies)
1014 # define BOOST_FOREACH_SHOULD_COPY(COL)                                                         \
1015     (true ? BOOST_FOREACH_NULL : BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(COL))
1016 
1017 #endif
1018 
1019 #define BOOST_FOREACH_CONTAIN(COL)                                                              \
1020     boost::foreach_detail_::contain(                                                            \
1021         BOOST_FOREACH_EVALUATE(COL)                                                             \
1022       , BOOST_FOREACH_SHOULD_COPY(COL))
1023 
1024 #define BOOST_FOREACH_BEGIN(COL)                                                                \
1025     boost::foreach_detail_::begin(                                                              \
1026         BOOST_FOREACH_ID(_foreach_col)                                                          \
1027       , BOOST_FOREACH_TYPEOF(COL)                                                               \
1028       , BOOST_FOREACH_SHOULD_COPY(COL))
1029 
1030 #define BOOST_FOREACH_END(COL)                                                                  \
1031     boost::foreach_detail_::end(                                                                \
1032         BOOST_FOREACH_ID(_foreach_col)                                                          \
1033       , BOOST_FOREACH_TYPEOF(COL)                                                               \
1034       , BOOST_FOREACH_SHOULD_COPY(COL))
1035 
1036 #define BOOST_FOREACH_DONE(COL)                                                                 \
1037     boost::foreach_detail_::done(                                                               \
1038         BOOST_FOREACH_ID(_foreach_cur)                                                          \
1039       , BOOST_FOREACH_ID(_foreach_end)                                                          \
1040       , BOOST_FOREACH_TYPEOF(COL))
1041 
1042 #define BOOST_FOREACH_NEXT(COL)                                                                 \
1043     boost::foreach_detail_::next(                                                               \
1044         BOOST_FOREACH_ID(_foreach_cur)                                                          \
1045       , BOOST_FOREACH_TYPEOF(COL))
1046 
1047 #define BOOST_FOREACH_DEREF(COL)                                                                \
1048     boost::foreach_detail_::deref(                                                              \
1049         BOOST_FOREACH_ID(_foreach_cur)                                                          \
1050       , BOOST_FOREACH_TYPEOF(COL))
1051 
1052 #define BOOST_FOREACH_RBEGIN(COL)                                                               \
1053     boost::foreach_detail_::rbegin(                                                             \
1054         BOOST_FOREACH_ID(_foreach_col)                                                          \
1055       , BOOST_FOREACH_TYPEOF(COL)                                                               \
1056       , BOOST_FOREACH_SHOULD_COPY(COL))
1057 
1058 #define BOOST_FOREACH_REND(COL)                                                                 \
1059     boost::foreach_detail_::rend(                                                               \
1060         BOOST_FOREACH_ID(_foreach_col)                                                          \
1061       , BOOST_FOREACH_TYPEOF(COL)                                                               \
1062       , BOOST_FOREACH_SHOULD_COPY(COL))
1063 
1064 #define BOOST_FOREACH_RDONE(COL)                                                                \
1065     boost::foreach_detail_::rdone(                                                              \
1066         BOOST_FOREACH_ID(_foreach_cur)                                                          \
1067       , BOOST_FOREACH_ID(_foreach_end)                                                          \
1068       , BOOST_FOREACH_TYPEOF(COL))
1069 
1070 #define BOOST_FOREACH_RNEXT(COL)                                                                \
1071     boost::foreach_detail_::rnext(                                                              \
1072         BOOST_FOREACH_ID(_foreach_cur)                                                          \
1073       , BOOST_FOREACH_TYPEOF(COL))
1074 
1075 #define BOOST_FOREACH_RDEREF(COL)                                                               \
1076     boost::foreach_detail_::rderef(                                                             \
1077         BOOST_FOREACH_ID(_foreach_cur)                                                          \
1078       , BOOST_FOREACH_TYPEOF(COL))
1079 
1080 ///////////////////////////////////////////////////////////////////////////////
1081 // BOOST_FOREACH
1082 //
1083 //   For iterating over collections. Collections can be
1084 //   arrays, null-terminated strings, or STL containers.
1085 //   The loop variable can be a value or reference. For
1086 //   example:
1087 //
1088 //   std::list<int> int_list(/*stuff*/);
1089 //   BOOST_FOREACH(int &i, int_list)
1090 //   {
1091 //       /* 
1092 //        * loop body goes here.
1093 //        * i is a reference to the int in int_list.
1094 //        */
1095 //   }
1096 //
1097 //   Alternately, you can declare the loop variable first,
1098 //   so you can access it after the loop finishes. Obviously,
1099 //   if you do it this way, then the loop variable cannot be
1100 //   a reference.
1101 //
1102 //   int i;
1103 //   BOOST_FOREACH(i, int_list)
1104 //       { ... }
1105 //
1106 #define BOOST_FOREACH(VAR, COL)                                                                                   \
1107     BOOST_FOREACH_PREAMBLE()                                                                                      \
1108     if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_col) = BOOST_FOREACH_CONTAIN(COL)) {} else   \
1109     if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_cur) = BOOST_FOREACH_BEGIN(COL)) {} else     \
1110     if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_end) = BOOST_FOREACH_END(COL)) {} else       \
1111     for (bool BOOST_FOREACH_ID(_foreach_continue) = true;                                                         \
1112               BOOST_FOREACH_ID(_foreach_continue) && !BOOST_FOREACH_DONE(COL);                                    \
1113               BOOST_FOREACH_ID(_foreach_continue) ? BOOST_FOREACH_NEXT(COL) : (void)0)                            \
1114         if  (boost::foreach_detail_::set_false(BOOST_FOREACH_ID(_foreach_continue))) {} else                      \
1115         for (VAR = BOOST_FOREACH_DEREF(COL); !BOOST_FOREACH_ID(_foreach_continue); BOOST_FOREACH_ID(_foreach_continue) = true)
1116 
1117 ///////////////////////////////////////////////////////////////////////////////
1118 // BOOST_REVERSE_FOREACH
1119 //
1120 //   For iterating over collections in reverse order. In
1121 //   all other respects, BOOST_REVERSE_FOREACH is like
1122 //   BOOST_FOREACH.
1123 //
1124 #define BOOST_REVERSE_FOREACH(VAR, COL)                                                                           \
1125     BOOST_FOREACH_PREAMBLE()                                                                                      \
1126     if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_col) = BOOST_FOREACH_CONTAIN(COL)) {} else   \
1127     if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_cur) = BOOST_FOREACH_RBEGIN(COL)) {} else    \
1128     if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_end) = BOOST_FOREACH_REND(COL)) {} else      \
1129     for (bool BOOST_FOREACH_ID(_foreach_continue) = true;                                                         \
1130               BOOST_FOREACH_ID(_foreach_continue) && !BOOST_FOREACH_RDONE(COL);                                   \
1131               BOOST_FOREACH_ID(_foreach_continue) ? BOOST_FOREACH_RNEXT(COL) : (void)0)                           \
1132         if  (boost::foreach_detail_::set_false(BOOST_FOREACH_ID(_foreach_continue))) {} else                      \
1133         for (VAR = BOOST_FOREACH_RDEREF(COL); !BOOST_FOREACH_ID(_foreach_continue); BOOST_FOREACH_ID(_foreach_continue) = true)
1134 
1135 #endif