Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // foreach.hpp header file Chris@16: // Chris@16: // Copyright 2004 Eric Niebler. Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: // See http://www.boost.org/libs/foreach for documentation Chris@16: // Chris@16: // Credits: Chris@16: // Anson Tsao - for the initial inspiration and several good suggestions. Chris@16: // Thorsten Ottosen - for Boost.Range, and for suggesting a way to detect Chris@16: // const-qualified rvalues at compile time on VC7.1+ Chris@16: // Russell Hind - For help porting to Borland Chris@16: // Alisdair Meredith - For help porting to Borland Chris@16: // Stefan Slapeta - For help porting to Intel Chris@16: // David Jenkins - For help finding a Microsoft Code Analysis bug Chris@16: // mimomorin@... - For a patch to use rvalue refs on supporting compilers Chris@16: Chris@16: #ifndef BOOST_FOREACH Chris@16: Chris@16: // MS compatible compilers support #pragma once Chris@101: #if defined(_MSC_VER) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include // for std::pair Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: // Some compilers let us detect even const-qualified rvalues at compile-time Chris@16: #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) \ Chris@101: || defined(BOOST_MSVC) && !defined(_PREFAST_) \ Chris@16: || (BOOST_WORKAROUND(__GNUC__, == 4) && (__GNUC_MINOR__ <= 5) && !defined(BOOST_INTEL) && \ Chris@16: !defined(BOOST_CLANG)) \ Chris@16: || (BOOST_WORKAROUND(__GNUC__, == 3) && (__GNUC_MINOR__ >= 4) && !defined(BOOST_INTEL) && \ Chris@16: !defined(BOOST_CLANG)) Chris@16: # define BOOST_FOREACH_COMPILE_TIME_CONST_RVALUE_DETECTION Chris@16: #else Chris@16: // Some compilers allow temporaries to be bound to non-const references. Chris@16: // These compilers make it impossible to for BOOST_FOREACH to detect Chris@16: // temporaries and avoid reevaluation of the collection expression. Chris@101: # if BOOST_WORKAROUND(__BORLANDC__, < 0x593) \ Chris@16: || (BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 700) && defined(_MSC_VER)) \ Chris@16: || BOOST_WORKAROUND(__SUNPRO_CC, < 0x5100) \ Chris@16: || BOOST_WORKAROUND(__DECCXX_VER, <= 60590042) Chris@16: # define BOOST_FOREACH_NO_RVALUE_DETECTION Chris@16: # endif Chris@16: // Some compilers do not correctly implement the lvalue/rvalue conversion Chris@16: // rules of the ternary conditional operator. Chris@16: # if defined(BOOST_FOREACH_NO_RVALUE_DETECTION) \ Chris@16: || defined(BOOST_NO_SFINAE) \ Chris@16: || BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1400)) \ Chris@16: || BOOST_WORKAROUND(BOOST_INTEL_WIN, BOOST_TESTED_AT(1400)) \ Chris@16: || (BOOST_WORKAROUND(__GNUC__, == 3) && (__GNUC_MINOR__ <= 3) && defined(__APPLE_CC__)) \ Chris@16: || BOOST_WORKAROUND(__IBMCPP__, BOOST_TESTED_AT(600)) \ Chris@16: || BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206)) \ Chris@16: || BOOST_WORKAROUND(__SUNPRO_CC, >= 0x5100) \ Chris@16: || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x590)) Chris@16: # define BOOST_FOREACH_NO_CONST_RVALUE_DETECTION Chris@16: # else Chris@16: # define BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION Chris@16: # endif Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: #endif Chris@16: Chris@16: namespace boost Chris@16: { Chris@16: Chris@16: // forward declarations for iterator_range Chris@16: template Chris@16: class iterator_range; Chris@16: Chris@16: // forward declarations for sub_range Chris@16: template Chris@16: class sub_range; Chris@16: Chris@16: namespace foreach Chris@16: { Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // in_range Chris@16: // Chris@16: template Chris@16: inline std::pair in_range(T begin, T end) Chris@16: { Chris@16: return std::make_pair(begin, end); Chris@16: } Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // boost::foreach::is_lightweight_proxy Chris@16: // Specialize this for user-defined collection types if they are inexpensive to copy. Chris@16: // This tells BOOST_FOREACH it can avoid the rvalue/lvalue detection stuff. Chris@16: template Chris@16: struct is_lightweight_proxy Chris@16: : boost::mpl::false_ Chris@16: { Chris@16: }; Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // boost::foreach::is_noncopyable Chris@16: // Specialize this for user-defined collection types if they cannot be copied. Chris@16: // This also tells BOOST_FOREACH to avoid the rvalue/lvalue detection stuff. Chris@16: template Chris@16: struct is_noncopyable Chris@16: #if !defined(BOOST_BROKEN_IS_BASE_AND_DERIVED) && !defined(BOOST_NO_IS_ABSTRACT) Chris@16: : boost::mpl::or_< Chris@16: boost::is_abstract Chris@16: , boost::is_base_and_derived Chris@16: > Chris@16: #elif !defined(BOOST_BROKEN_IS_BASE_AND_DERIVED) Chris@16: : boost::is_base_and_derived Chris@16: #elif !defined(BOOST_NO_IS_ABSTRACT) Chris@16: : boost::is_abstract Chris@16: #else Chris@16: : boost::mpl::false_ Chris@16: #endif Chris@16: { Chris@16: }; Chris@16: Chris@16: } // namespace foreach Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: // vc6/7 needs help ordering the following overloads Chris@16: #ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING Chris@16: # define BOOST_FOREACH_TAG_DEFAULT ... Chris@16: #else Chris@16: # define BOOST_FOREACH_TAG_DEFAULT boost::foreach::tag Chris@16: #endif Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // boost_foreach_is_lightweight_proxy Chris@16: // Another customization point for the is_lightweight_proxy optimization, Chris@16: // this one works on legacy compilers. Overload boost_foreach_is_lightweight_proxy Chris@16: // at the global namespace for your type. Chris@16: template Chris@16: inline boost::foreach::is_lightweight_proxy * Chris@16: boost_foreach_is_lightweight_proxy(T *&, BOOST_FOREACH_TAG_DEFAULT) { return 0; } Chris@16: Chris@16: template Chris@16: inline boost::mpl::true_ * Chris@16: boost_foreach_is_lightweight_proxy(std::pair *&, boost::foreach::tag) { return 0; } Chris@16: Chris@16: template Chris@16: inline boost::mpl::true_ * Chris@16: boost_foreach_is_lightweight_proxy(boost::iterator_range *&, boost::foreach::tag) { return 0; } Chris@16: Chris@16: template Chris@16: inline boost::mpl::true_ * Chris@16: boost_foreach_is_lightweight_proxy(boost::sub_range *&, boost::foreach::tag) { return 0; } Chris@16: Chris@16: template Chris@16: inline boost::mpl::true_ * Chris@16: boost_foreach_is_lightweight_proxy(T **&, boost::foreach::tag) { return 0; } Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // boost_foreach_is_noncopyable Chris@16: // Another customization point for the is_noncopyable trait, Chris@16: // this one works on legacy compilers. Overload boost_foreach_is_noncopyable Chris@16: // at the global namespace for your type. Chris@16: template Chris@16: inline boost::foreach::is_noncopyable * Chris@16: boost_foreach_is_noncopyable(T *&, BOOST_FOREACH_TAG_DEFAULT) { return 0; } Chris@16: Chris@16: namespace boost Chris@16: { Chris@16: Chris@16: namespace foreach_detail_ Chris@16: { Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // Define some utilities for assessing the properties of expressions Chris@16: // Chris@16: template Chris@16: inline boost::mpl::and_ *and_(Bool1 *, Bool2 *) { return 0; } Chris@16: Chris@16: template Chris@16: inline boost::mpl::and_ *and_(Bool1 *, Bool2 *, Bool3 *) { return 0; } Chris@16: Chris@16: template Chris@16: inline boost::mpl::or_ *or_(Bool1 *, Bool2 *) { return 0; } Chris@16: Chris@16: template Chris@16: inline boost::mpl::or_ *or_(Bool1 *, Bool2 *, Bool3 *) { return 0; } Chris@16: Chris@16: template Chris@16: inline boost::mpl::not_ *not_(Bool1 *) { return 0; } Chris@16: Chris@16: template Chris@16: inline boost::is_array *is_array_(T const &) { return 0; } Chris@16: Chris@16: template Chris@16: inline boost::is_const *is_const_(T &) { return 0; } Chris@16: Chris@16: #ifndef BOOST_FOREACH_NO_RVALUE_DETECTION Chris@16: template Chris@16: inline boost::mpl::true_ *is_const_(T const &) { return 0; } Chris@16: #endif Chris@16: Chris@16: #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES Chris@16: template Chris@16: inline boost::mpl::false_ *is_rvalue_(T &, int) { return 0; } Chris@16: Chris@16: template Chris@16: inline boost::mpl::true_ *is_rvalue_(T const &, ...) { return 0; } Chris@16: #else Chris@16: template Chris@16: inline boost::is_rvalue_reference *is_rvalue_(T &&, int) { return 0; } Chris@16: #endif Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // auto_any_t/auto_any Chris@16: // General utility for putting an object of any type into automatic storage Chris@16: struct auto_any_base Chris@16: { Chris@16: // auto_any_base must evaluate to false in boolean context so that Chris@16: // they can be declared in if() statements. Chris@16: operator bool() const Chris@16: { Chris@16: return false; Chris@16: } Chris@16: }; Chris@16: Chris@16: template Chris@16: struct auto_any : auto_any_base Chris@16: { Chris@16: explicit auto_any(T const &t) Chris@16: : item(t) Chris@16: { Chris@16: } Chris@16: Chris@16: // temporaries of type auto_any will be bound to const auto_any_base Chris@16: // references, but we still want to be able to mutate the stored Chris@16: // data, so declare it as mutable. Chris@16: mutable T item; Chris@16: }; Chris@16: Chris@16: typedef auto_any_base const &auto_any_t; Chris@16: Chris@16: template Chris@16: inline BOOST_DEDUCED_TYPENAME boost::mpl::if_::type &auto_any_cast(auto_any_t a) Chris@16: { Chris@16: return static_cast const &>(a).item; Chris@16: } Chris@16: Chris@16: typedef boost::mpl::true_ const_; Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // type2type Chris@16: // Chris@16: template Chris@16: struct type2type Chris@16: : boost::mpl::if_ Chris@16: { Chris@16: }; Chris@16: Chris@16: template Chris@16: struct wrap_cstr Chris@16: { Chris@16: typedef T type; Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct wrap_cstr Chris@16: { Chris@16: typedef wrap_cstr type; Chris@16: typedef char *iterator; Chris@16: typedef char *const_iterator; Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct wrap_cstr Chris@16: { Chris@16: typedef wrap_cstr type; Chris@16: typedef char const *iterator; Chris@16: typedef char const *const_iterator; Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct wrap_cstr Chris@16: { Chris@16: typedef wrap_cstr type; Chris@16: typedef wchar_t *iterator; Chris@16: typedef wchar_t *const_iterator; Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct wrap_cstr Chris@16: { Chris@16: typedef wrap_cstr type; Chris@16: typedef wchar_t const *iterator; Chris@16: typedef wchar_t const *const_iterator; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct is_char_array Chris@16: : mpl::and_< Chris@16: is_array Chris@16: , mpl::or_< Chris@16: is_convertible Chris@16: , is_convertible Chris@16: > Chris@16: > Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct foreach_iterator Chris@16: { Chris@16: // **** READ THIS IF YOUR COMPILE BREAKS HERE **** Chris@16: // Chris@16: // There is an ambiguity about how to iterate over arrays of char and wchar_t. Chris@16: // Should the last array element be treated as a null terminator to be skipped, or Chris@16: // is it just like any other element in the array? To fix the problem, you must Chris@16: // say which behavior you want. Chris@16: // Chris@16: // To treat the container as a null-terminated string, merely cast it to a Chris@16: // char const *, as in BOOST_FOREACH( char ch, (char const *)"hello" ) ... Chris@16: // Chris@16: // To treat the container as an array, use boost::as_array() in , Chris@16: // as in BOOST_FOREACH( char ch, boost::as_array("hello") ) ... Chris@16: BOOST_MPL_ASSERT_MSG( (!is_char_array::value), IS_THIS_AN_ARRAY_OR_A_NULL_TERMINATED_STRING, (T&) ); Chris@16: Chris@16: // If the type is a pointer to a null terminated string (as opposed Chris@16: // to an array type), there is no ambiguity. Chris@16: typedef BOOST_DEDUCED_TYPENAME wrap_cstr::type container; Chris@16: Chris@16: typedef BOOST_DEDUCED_TYPENAME boost::mpl::eval_if< Chris@16: C Chris@16: , range_const_iterator Chris@16: , range_mutable_iterator Chris@16: >::type type; Chris@16: }; Chris@16: Chris@16: Chris@16: template Chris@16: struct foreach_reverse_iterator Chris@16: { Chris@16: // **** READ THIS IF YOUR COMPILE BREAKS HERE **** Chris@16: // Chris@16: // There is an ambiguity about how to iterate over arrays of char and wchar_t. Chris@16: // Should the last array element be treated as a null terminator to be skipped, or Chris@16: // is it just like any other element in the array? To fix the problem, you must Chris@16: // say which behavior you want. Chris@16: // Chris@16: // To treat the container as a null-terminated string, merely cast it to a Chris@16: // char const *, as in BOOST_FOREACH( char ch, (char const *)"hello" ) ... Chris@16: // Chris@16: // To treat the container as an array, use boost::as_array() in , Chris@16: // as in BOOST_FOREACH( char ch, boost::as_array("hello") ) ... Chris@16: BOOST_MPL_ASSERT_MSG( (!is_char_array::value), IS_THIS_AN_ARRAY_OR_A_NULL_TERMINATED_STRING, (T&) ); Chris@16: Chris@16: // If the type is a pointer to a null terminated string (as opposed Chris@16: // to an array type), there is no ambiguity. Chris@16: typedef BOOST_DEDUCED_TYPENAME wrap_cstr::type container; Chris@16: Chris@16: typedef BOOST_DEDUCED_TYPENAME boost::mpl::eval_if< Chris@16: C Chris@16: , range_reverse_iterator Chris@16: , range_reverse_iterator Chris@16: >::type type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct foreach_reference Chris@16: : iterator_reference::type> Chris@16: { Chris@16: }; Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // encode_type Chris@16: // Chris@16: template Chris@101: inline type2type *encode_type(T &, boost::false_type*) { return 0; } Chris@16: Chris@16: template Chris@101: inline type2type *encode_type(T const &, boost::true_type*) { return 0; } Chris@101: Chris@101: template Chris@101: inline type2type *encode_type(T &, boost::mpl::false_*) { return 0; } Chris@101: Chris@101: template Chris@101: inline type2type *encode_type(T const &, boost::mpl::true_*) { return 0; } Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // set_false Chris@16: // Chris@16: inline bool set_false(bool &b) Chris@16: { Chris@16: b = false; Chris@16: return false; Chris@16: } Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // to_ptr Chris@16: // Chris@16: template Chris@16: inline T *&to_ptr(T const &) Chris@16: { Chris@16: static T *t = 0; Chris@16: return t; Chris@16: } Chris@16: Chris@16: // Borland needs a little extra help with arrays Chris@16: #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) Chris@16: template Chris@16: inline T (*&to_ptr(T (&)[N]))[N] Chris@16: { Chris@16: static T (*t)[N] = 0; Chris@16: return t; Chris@16: } Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // derefof Chris@16: // Chris@16: template Chris@16: inline T &derefof(T *t) Chris@16: { Chris@16: // This is a work-around for a compiler bug in Borland. If T* is a pointer to array type U(*)[N], Chris@16: // then dereferencing it results in a U* instead of U(&)[N]. The cast forces the issue. Chris@16: return reinterpret_cast( Chris@16: *const_cast( Chris@16: reinterpret_cast(t) Chris@16: ) Chris@16: ); Chris@16: } Chris@16: Chris@16: # define BOOST_FOREACH_DEREFOF(T) boost::foreach_detail_::derefof(*T) Chris@16: #else Chris@16: # define BOOST_FOREACH_DEREFOF(T) (*T) Chris@16: #endif Chris@16: Chris@16: #if defined(BOOST_FOREACH_COMPILE_TIME_CONST_RVALUE_DETECTION) \ Chris@16: && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // Rvalue references makes it drop-dead simple to detect at compile time Chris@16: // whether an expression is an rvalue. Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: # define BOOST_FOREACH_IS_RVALUE(COL) \ Chris@16: boost::foreach_detail_::is_rvalue_((COL), 0) Chris@16: Chris@16: #elif defined(BOOST_FOREACH_COMPILE_TIME_CONST_RVALUE_DETECTION) \ Chris@16: && defined(BOOST_NO_CXX11_RVALUE_REFERENCES) Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // Detect at compile-time whether an expression yields an rvalue or Chris@16: // an lvalue. This is rather non-standard, but some popular compilers Chris@16: // accept it. Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // rvalue_probe Chris@16: // Chris@16: template Chris@16: struct rvalue_probe Chris@16: { Chris@16: struct private_type_ {}; Chris@16: // can't ever return an array by value Chris@16: typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_< Chris@16: boost::mpl::or_, boost::is_array >, private_type_, T Chris@16: >::type value_type; Chris@16: operator value_type() { return *reinterpret_cast(this); } // never called Chris@16: operator T &() const { return *reinterpret_cast(const_cast(this)); } // never called Chris@16: }; Chris@16: Chris@16: template Chris@16: rvalue_probe const make_probe(T const &) Chris@16: { Chris@16: return rvalue_probe(); Chris@16: } Chris@16: Chris@16: # define BOOST_FOREACH_IS_RVALUE(COL) \ Chris@16: boost::foreach_detail_::and_( \ Chris@16: boost::foreach_detail_::not_(boost::foreach_detail_::is_array_(COL)) \ Chris@16: , (true ? 0 : boost::foreach_detail_::is_rvalue_( \ Chris@16: (true ? boost::foreach_detail_::make_probe(COL) : (COL)), 0))) Chris@16: Chris@16: #elif defined(BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION) Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // Detect at run-time whether an expression yields an rvalue Chris@16: // or an lvalue. This is 100% standard C++, but not all compilers Chris@16: // accept it. Also, it causes FOREACH to break when used with non- Chris@16: // copyable collection types. Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // rvalue_probe Chris@16: // Chris@16: template Chris@16: struct rvalue_probe Chris@16: { Chris@16: rvalue_probe(T &t, bool &b) Chris@16: : value(t) Chris@16: , is_rvalue(b) Chris@16: { Chris@16: } Chris@16: Chris@16: struct private_type_ {}; Chris@16: // can't ever return an array or an abstract type by value Chris@16: #ifdef BOOST_NO_IS_ABSTRACT Chris@16: typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_< Chris@16: boost::is_array, private_type_, T Chris@16: >::type value_type; Chris@16: #else Chris@16: typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_< Chris@16: boost::mpl::or_, boost::is_array >, private_type_, T Chris@16: >::type value_type; Chris@16: #endif Chris@16: Chris@16: operator value_type() Chris@16: { Chris@16: this->is_rvalue = true; Chris@16: return this->value; Chris@16: } Chris@16: Chris@16: operator T &() const Chris@16: { Chris@16: return this->value; Chris@16: } Chris@16: Chris@16: private: Chris@16: T &value; Chris@16: bool &is_rvalue; Chris@16: }; Chris@16: Chris@16: template Chris@16: rvalue_probe make_probe(T &t, bool &b) { return rvalue_probe(t, b); } Chris@16: Chris@16: template Chris@16: rvalue_probe make_probe(T const &t, bool &b) { return rvalue_probe(t, b); } Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // simple_variant Chris@16: // holds either a T or a T const* Chris@16: template Chris@16: struct simple_variant Chris@16: { Chris@16: simple_variant(T const *t) Chris@16: : is_rvalue(false) Chris@16: { Chris@16: *static_cast(this->data.address()) = t; Chris@16: } Chris@16: Chris@16: simple_variant(T const &t) Chris@16: : is_rvalue(true) Chris@16: { Chris@16: ::new(this->data.address()) T(t); Chris@16: } Chris@16: Chris@16: simple_variant(simple_variant const &that) Chris@16: : is_rvalue(that.is_rvalue) Chris@16: { Chris@16: if(this->is_rvalue) Chris@16: ::new(this->data.address()) T(*that.get()); Chris@16: else Chris@16: *static_cast(this->data.address()) = that.get(); Chris@16: } Chris@16: Chris@16: ~simple_variant() Chris@16: { Chris@16: if(this->is_rvalue) Chris@16: this->get()->~T(); Chris@16: } Chris@16: Chris@16: T const *get() const Chris@16: { Chris@16: if(this->is_rvalue) Chris@16: return static_cast(this->data.address()); Chris@16: else Chris@16: return *static_cast(this->data.address()); Chris@16: } Chris@16: Chris@16: private: Chris@16: enum size_type { size = sizeof(T) > sizeof(T*) ? sizeof(T) : sizeof(T*) }; Chris@16: simple_variant &operator =(simple_variant const &); Chris@16: bool const is_rvalue; Chris@16: aligned_storage data; Chris@16: }; Chris@16: Chris@16: // If the collection is an array or is noncopyable, it must be an lvalue. Chris@16: // If the collection is a lightweight proxy, treat it as an rvalue Chris@16: // BUGBUG what about a noncopyable proxy? Chris@16: template Chris@16: inline BOOST_DEDUCED_TYPENAME boost::enable_if, IsProxy>::type * Chris@16: should_copy_impl(LValue *, IsProxy *, bool *) Chris@16: { Chris@16: return 0; Chris@16: } Chris@16: Chris@16: // Otherwise, we must determine at runtime whether it's an lvalue or rvalue Chris@16: inline bool * Chris@16: should_copy_impl(boost::mpl::false_ *, boost::mpl::false_ *, bool *is_rvalue) Chris@16: { Chris@16: return is_rvalue; Chris@16: } Chris@16: Chris@16: #endif Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // contain Chris@16: // Chris@16: template Chris@16: inline auto_any contain(T const &t, boost::mpl::true_ *) // rvalue Chris@16: { Chris@16: return auto_any(t); Chris@16: } Chris@16: Chris@16: template Chris@16: inline auto_any contain(T &t, boost::mpl::false_ *) // lvalue Chris@16: { Chris@16: // Cannot seem to get sunpro to handle addressof() with array types. Chris@16: #if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x570)) Chris@16: return auto_any(&t); Chris@16: #else Chris@16: return auto_any(boost::addressof(t)); Chris@16: #endif Chris@16: } Chris@16: Chris@16: #ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION Chris@16: template Chris@16: inline auto_any > Chris@16: contain(T const &t, bool *rvalue) Chris@16: { Chris@16: return auto_any >(*rvalue ? simple_variant(t) : simple_variant(&t)); Chris@16: } Chris@16: #endif Chris@16: Chris@16: ///////////////////////////////////////////////////////////////////////////// Chris@16: // begin Chris@16: // Chris@16: template Chris@16: inline auto_any::type> Chris@16: begin(auto_any_t col, type2type *, boost::mpl::true_ *) // rvalue Chris@16: { Chris@16: return auto_any::type>( Chris@16: boost::begin(auto_any_cast(col))); Chris@16: } Chris@16: Chris@16: template Chris@16: inline auto_any::type> Chris@16: begin(auto_any_t col, type2type *, boost::mpl::false_ *) // lvalue Chris@16: { Chris@16: typedef BOOST_DEDUCED_TYPENAME type2type::type type; Chris@16: typedef BOOST_DEDUCED_TYPENAME foreach_iterator::type iterator; Chris@16: return auto_any::type>( Chris@16: iterator(boost::begin(BOOST_FOREACH_DEREFOF((auto_any_cast(col)))))); Chris@16: } Chris@16: Chris@16: #ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION Chris@16: template Chris@16: inline auto_any::type> Chris@16: begin(auto_any_t col, type2type *, bool *) Chris@16: { Chris@16: return auto_any::type>( Chris@16: boost::begin(*auto_any_cast, boost::mpl::false_>(col).get())); Chris@16: } Chris@16: #endif Chris@16: Chris@16: #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING Chris@16: template Chris@16: inline auto_any Chris@16: begin(auto_any_t col, type2type *, boost::mpl::true_ *) // null-terminated C-style strings Chris@16: { Chris@16: return auto_any(auto_any_cast(col)); Chris@16: } Chris@16: #endif Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // end Chris@16: // Chris@16: template Chris@16: inline auto_any::type> Chris@16: end(auto_any_t col, type2type *, boost::mpl::true_ *) // rvalue Chris@16: { Chris@16: return auto_any::type>( Chris@16: boost::end(auto_any_cast(col))); Chris@16: } Chris@16: Chris@16: template Chris@16: inline auto_any::type> Chris@16: end(auto_any_t col, type2type *, boost::mpl::false_ *) // lvalue Chris@16: { Chris@16: typedef BOOST_DEDUCED_TYPENAME type2type::type type; Chris@16: typedef BOOST_DEDUCED_TYPENAME foreach_iterator::type iterator; Chris@16: return auto_any::type>( Chris@16: iterator(boost::end(BOOST_FOREACH_DEREFOF((auto_any_cast(col)))))); Chris@16: } Chris@16: Chris@16: #ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION Chris@16: template Chris@16: inline auto_any::type> Chris@16: end(auto_any_t col, type2type *, bool *) Chris@16: { Chris@16: return auto_any::type>( Chris@16: boost::end(*auto_any_cast, boost::mpl::false_>(col).get())); Chris@16: } Chris@16: #endif Chris@16: Chris@16: #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING Chris@16: template Chris@16: inline auto_any Chris@16: end(auto_any_t, type2type *, boost::mpl::true_ *) // null-terminated C-style strings Chris@16: { Chris@16: return auto_any(0); // not used Chris@16: } Chris@16: #endif Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // done Chris@16: // Chris@16: template Chris@16: inline bool done(auto_any_t cur, auto_any_t end, type2type *) Chris@16: { Chris@16: typedef BOOST_DEDUCED_TYPENAME foreach_iterator::type iter_t; Chris@16: return auto_any_cast(cur) == auto_any_cast(end); Chris@16: } Chris@16: Chris@16: #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING Chris@16: template Chris@16: inline bool done(auto_any_t cur, auto_any_t, type2type *) // null-terminated C-style strings Chris@16: { Chris@16: return ! *auto_any_cast(cur); Chris@16: } Chris@16: #endif Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // next Chris@16: // Chris@16: template Chris@16: inline void next(auto_any_t cur, type2type *) Chris@16: { Chris@16: typedef BOOST_DEDUCED_TYPENAME foreach_iterator::type iter_t; Chris@16: ++auto_any_cast(cur); Chris@16: } Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // deref Chris@16: // Chris@16: template Chris@16: inline BOOST_DEDUCED_TYPENAME foreach_reference::type Chris@16: deref(auto_any_t cur, type2type *) Chris@16: { Chris@16: typedef BOOST_DEDUCED_TYPENAME foreach_iterator::type iter_t; Chris@16: return *auto_any_cast(cur); Chris@16: } Chris@16: Chris@16: ///////////////////////////////////////////////////////////////////////////// Chris@16: // rbegin Chris@16: // Chris@16: template Chris@16: inline auto_any::type> Chris@16: rbegin(auto_any_t col, type2type *, boost::mpl::true_ *) // rvalue Chris@16: { Chris@16: return auto_any::type>( Chris@16: boost::rbegin(auto_any_cast(col))); Chris@16: } Chris@16: Chris@16: template Chris@16: inline auto_any::type> Chris@16: rbegin(auto_any_t col, type2type *, boost::mpl::false_ *) // lvalue Chris@16: { Chris@16: typedef BOOST_DEDUCED_TYPENAME type2type::type type; Chris@16: typedef BOOST_DEDUCED_TYPENAME foreach_reverse_iterator::type iterator; Chris@16: return auto_any::type>( Chris@16: iterator(boost::rbegin(BOOST_FOREACH_DEREFOF((auto_any_cast(col)))))); Chris@16: } Chris@16: Chris@16: #ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION Chris@16: template Chris@16: inline auto_any::type> Chris@16: rbegin(auto_any_t col, type2type *, bool *) Chris@16: { Chris@16: return auto_any::type>( Chris@16: boost::rbegin(*auto_any_cast, boost::mpl::false_>(col).get())); Chris@16: } Chris@16: #endif Chris@16: Chris@16: #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING Chris@16: template Chris@16: inline auto_any > Chris@16: rbegin(auto_any_t col, type2type *, boost::mpl::true_ *) // null-terminated C-style strings Chris@16: { Chris@16: T *p = auto_any_cast(col); Chris@16: while(0 != *p) Chris@16: ++p; Chris@16: return auto_any >(reverse_iterator(p)); Chris@16: } Chris@16: #endif Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // rend Chris@16: // Chris@16: template Chris@16: inline auto_any::type> Chris@16: rend(auto_any_t col, type2type *, boost::mpl::true_ *) // rvalue Chris@16: { Chris@16: return auto_any::type>( Chris@16: boost::rend(auto_any_cast(col))); Chris@16: } Chris@16: Chris@16: template Chris@16: inline auto_any::type> Chris@16: rend(auto_any_t col, type2type *, boost::mpl::false_ *) // lvalue Chris@16: { Chris@16: typedef BOOST_DEDUCED_TYPENAME type2type::type type; Chris@16: typedef BOOST_DEDUCED_TYPENAME foreach_reverse_iterator::type iterator; Chris@16: return auto_any::type>( Chris@16: iterator(boost::rend(BOOST_FOREACH_DEREFOF((auto_any_cast(col)))))); Chris@16: } Chris@16: Chris@16: #ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION Chris@16: template Chris@16: inline auto_any::type> Chris@16: rend(auto_any_t col, type2type *, bool *) Chris@16: { Chris@16: return auto_any::type>( Chris@16: boost::rend(*auto_any_cast, boost::mpl::false_>(col).get())); Chris@16: } Chris@16: #endif Chris@16: Chris@16: #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING Chris@16: template Chris@16: inline auto_any > Chris@16: rend(auto_any_t col, type2type *, boost::mpl::true_ *) // null-terminated C-style strings Chris@16: { Chris@16: return auto_any >( Chris@16: reverse_iterator(auto_any_cast(col))); Chris@16: } Chris@16: #endif Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // rdone Chris@16: // Chris@16: template Chris@16: inline bool rdone(auto_any_t cur, auto_any_t end, type2type *) Chris@16: { Chris@16: typedef BOOST_DEDUCED_TYPENAME foreach_reverse_iterator::type iter_t; Chris@16: return auto_any_cast(cur) == auto_any_cast(end); Chris@16: } Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // rnext Chris@16: // Chris@16: template Chris@16: inline void rnext(auto_any_t cur, type2type *) Chris@16: { Chris@16: typedef BOOST_DEDUCED_TYPENAME foreach_reverse_iterator::type iter_t; Chris@16: ++auto_any_cast(cur); Chris@16: } Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // rderef Chris@16: // Chris@16: template Chris@16: inline BOOST_DEDUCED_TYPENAME foreach_reference::type Chris@16: rderef(auto_any_t cur, type2type *) Chris@16: { Chris@16: typedef BOOST_DEDUCED_TYPENAME foreach_reverse_iterator::type iter_t; Chris@16: return *auto_any_cast(cur); Chris@16: } Chris@16: Chris@16: } // namespace foreach_detail_ Chris@16: } // namespace boost Chris@16: Chris@16: // Suppress a bogus code analysis warning on vc8+ Chris@16: #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) Chris@16: # define BOOST_FOREACH_SUPPRESS_WARNINGS() __pragma(warning(suppress:6001)) Chris@16: #else Chris@16: # define BOOST_FOREACH_SUPPRESS_WARNINGS() Chris@16: #endif Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // Define a macro for giving hidden variables a unique name. Not strictly Chris@16: // needed, but eliminates some warnings on some compilers. Chris@16: #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500)) Chris@16: // With some versions of MSVC, use of __LINE__ to create unique identifiers Chris@16: // can fail when the Edit-and-Continue debug flag is used. Chris@16: # define BOOST_FOREACH_ID(x) x Chris@16: #else Chris@16: # define BOOST_FOREACH_ID(x) BOOST_PP_CAT(x, __LINE__) Chris@16: #endif Chris@16: Chris@16: // A sneaky way to get the type of the collection without evaluating the expression Chris@16: #define BOOST_FOREACH_TYPEOF(COL) \ Chris@16: (true ? 0 : boost::foreach_detail_::encode_type(COL, boost::foreach_detail_::is_const_(COL))) Chris@16: Chris@16: // returns true_* if the type is noncopyable Chris@16: #define BOOST_FOREACH_IS_NONCOPYABLE(COL) \ Chris@16: boost_foreach_is_noncopyable( \ Chris@16: boost::foreach_detail_::to_ptr(COL) \ Chris@16: , boost_foreach_argument_dependent_lookup_hack_value) Chris@16: Chris@16: // returns true_* if the type is a lightweight proxy (and is not noncopyable) Chris@16: #define BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(COL) \ Chris@16: boost::foreach_detail_::and_( \ Chris@16: boost::foreach_detail_::not_(BOOST_FOREACH_IS_NONCOPYABLE(COL)) \ Chris@16: , boost_foreach_is_lightweight_proxy( \ Chris@16: boost::foreach_detail_::to_ptr(COL) \ Chris@16: , boost_foreach_argument_dependent_lookup_hack_value)) Chris@16: Chris@16: #if defined(BOOST_FOREACH_COMPILE_TIME_CONST_RVALUE_DETECTION) Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // R-values and const R-values supported here with zero runtime overhead Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: // No variable is needed to track the rvalue-ness of the collection expression Chris@16: # define BOOST_FOREACH_PREAMBLE() \ Chris@16: BOOST_FOREACH_SUPPRESS_WARNINGS() Chris@16: Chris@16: // Evaluate the collection expression Chris@16: # define BOOST_FOREACH_EVALUATE(COL) \ Chris@16: (COL) Chris@16: Chris@16: # define BOOST_FOREACH_SHOULD_COPY(COL) \ Chris@16: (true ? 0 : boost::foreach_detail_::or_( \ Chris@16: BOOST_FOREACH_IS_RVALUE(COL) \ Chris@16: , BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(COL))) Chris@16: Chris@16: #elif defined(BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION) Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // R-values and const R-values supported here Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: // Declare a variable to track the rvalue-ness of the collection expression Chris@16: # define BOOST_FOREACH_PREAMBLE() \ Chris@16: BOOST_FOREACH_SUPPRESS_WARNINGS() \ Chris@16: if (bool BOOST_FOREACH_ID(_foreach_is_rvalue) = false) {} else Chris@16: Chris@16: // Evaluate the collection expression, and detect if it is an lvalue or and rvalue Chris@16: # define BOOST_FOREACH_EVALUATE(COL) \ Chris@16: (true ? boost::foreach_detail_::make_probe((COL), BOOST_FOREACH_ID(_foreach_is_rvalue)) : (COL)) Chris@16: Chris@16: // The rvalue/lvalue-ness of the collection expression is determined dynamically, unless Chris@16: // the type is an array or is noncopyable or is non-const, in which case we know it's an lvalue. Chris@16: // If the type happens to be a lightweight proxy, always make a copy. Chris@16: # define BOOST_FOREACH_SHOULD_COPY(COL) \ Chris@16: (boost::foreach_detail_::should_copy_impl( \ Chris@16: true ? 0 : boost::foreach_detail_::or_( \ Chris@16: boost::foreach_detail_::is_array_(COL) \ Chris@16: , BOOST_FOREACH_IS_NONCOPYABLE(COL) \ Chris@16: , boost::foreach_detail_::not_(boost::foreach_detail_::is_const_(COL))) \ Chris@16: , true ? 0 : BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(COL) \ Chris@16: , &BOOST_FOREACH_ID(_foreach_is_rvalue))) Chris@16: Chris@16: #elif !defined(BOOST_FOREACH_NO_RVALUE_DETECTION) Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // R-values supported here, const R-values NOT supported here Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: // No variable is needed to track the rvalue-ness of the collection expression Chris@16: # define BOOST_FOREACH_PREAMBLE() \ Chris@16: BOOST_FOREACH_SUPPRESS_WARNINGS() Chris@16: Chris@16: // Evaluate the collection expression Chris@16: # define BOOST_FOREACH_EVALUATE(COL) \ Chris@16: (COL) Chris@16: Chris@16: // Determine whether the collection expression is an lvalue or an rvalue. Chris@16: // NOTE: this gets the answer wrong for const rvalues. Chris@16: # define BOOST_FOREACH_SHOULD_COPY(COL) \ Chris@16: (true ? 0 : boost::foreach_detail_::or_( \ Chris@16: boost::foreach_detail_::is_rvalue_((COL), 0) \ Chris@16: , BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(COL))) Chris@16: Chris@16: #else Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // R-values NOT supported here Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: // No variable is needed to track the rvalue-ness of the collection expression Chris@16: # define BOOST_FOREACH_PREAMBLE() \ Chris@16: BOOST_FOREACH_SUPPRESS_WARNINGS() Chris@16: Chris@16: // Evaluate the collection expression Chris@16: # define BOOST_FOREACH_EVALUATE(COL) \ Chris@16: (COL) Chris@16: Chris@16: // Can't use rvalues with BOOST_FOREACH (unless they are lightweight proxies) Chris@16: # define BOOST_FOREACH_SHOULD_COPY(COL) \ Chris@16: (true ? 0 : BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(COL)) Chris@16: Chris@16: #endif Chris@16: Chris@16: #define BOOST_FOREACH_CONTAIN(COL) \ Chris@16: boost::foreach_detail_::contain( \ Chris@16: BOOST_FOREACH_EVALUATE(COL) \ Chris@16: , BOOST_FOREACH_SHOULD_COPY(COL)) Chris@16: Chris@16: #define BOOST_FOREACH_BEGIN(COL) \ Chris@16: boost::foreach_detail_::begin( \ Chris@16: BOOST_FOREACH_ID(_foreach_col) \ Chris@16: , BOOST_FOREACH_TYPEOF(COL) \ Chris@16: , BOOST_FOREACH_SHOULD_COPY(COL)) Chris@16: Chris@16: #define BOOST_FOREACH_END(COL) \ Chris@16: boost::foreach_detail_::end( \ Chris@16: BOOST_FOREACH_ID(_foreach_col) \ Chris@16: , BOOST_FOREACH_TYPEOF(COL) \ Chris@16: , BOOST_FOREACH_SHOULD_COPY(COL)) Chris@16: Chris@16: #define BOOST_FOREACH_DONE(COL) \ Chris@16: boost::foreach_detail_::done( \ Chris@16: BOOST_FOREACH_ID(_foreach_cur) \ Chris@16: , BOOST_FOREACH_ID(_foreach_end) \ Chris@16: , BOOST_FOREACH_TYPEOF(COL)) Chris@16: Chris@16: #define BOOST_FOREACH_NEXT(COL) \ Chris@16: boost::foreach_detail_::next( \ Chris@16: BOOST_FOREACH_ID(_foreach_cur) \ Chris@16: , BOOST_FOREACH_TYPEOF(COL)) Chris@16: Chris@16: #define BOOST_FOREACH_DEREF(COL) \ Chris@16: boost::foreach_detail_::deref( \ Chris@16: BOOST_FOREACH_ID(_foreach_cur) \ Chris@16: , BOOST_FOREACH_TYPEOF(COL)) Chris@16: Chris@16: #define BOOST_FOREACH_RBEGIN(COL) \ Chris@16: boost::foreach_detail_::rbegin( \ Chris@16: BOOST_FOREACH_ID(_foreach_col) \ Chris@16: , BOOST_FOREACH_TYPEOF(COL) \ Chris@16: , BOOST_FOREACH_SHOULD_COPY(COL)) Chris@16: Chris@16: #define BOOST_FOREACH_REND(COL) \ Chris@16: boost::foreach_detail_::rend( \ Chris@16: BOOST_FOREACH_ID(_foreach_col) \ Chris@16: , BOOST_FOREACH_TYPEOF(COL) \ Chris@16: , BOOST_FOREACH_SHOULD_COPY(COL)) Chris@16: Chris@16: #define BOOST_FOREACH_RDONE(COL) \ Chris@16: boost::foreach_detail_::rdone( \ Chris@16: BOOST_FOREACH_ID(_foreach_cur) \ Chris@16: , BOOST_FOREACH_ID(_foreach_end) \ Chris@16: , BOOST_FOREACH_TYPEOF(COL)) Chris@16: Chris@16: #define BOOST_FOREACH_RNEXT(COL) \ Chris@16: boost::foreach_detail_::rnext( \ Chris@16: BOOST_FOREACH_ID(_foreach_cur) \ Chris@16: , BOOST_FOREACH_TYPEOF(COL)) Chris@16: Chris@16: #define BOOST_FOREACH_RDEREF(COL) \ Chris@16: boost::foreach_detail_::rderef( \ Chris@16: BOOST_FOREACH_ID(_foreach_cur) \ Chris@16: , BOOST_FOREACH_TYPEOF(COL)) Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // BOOST_FOREACH Chris@16: // Chris@16: // For iterating over collections. Collections can be Chris@16: // arrays, null-terminated strings, or STL containers. Chris@16: // The loop variable can be a value or reference. For Chris@16: // example: Chris@16: // Chris@16: // std::list int_list(/*stuff*/); Chris@16: // BOOST_FOREACH(int &i, int_list) Chris@16: // { Chris@16: // /* Chris@16: // * loop body goes here. Chris@16: // * i is a reference to the int in int_list. Chris@16: // */ Chris@16: // } Chris@16: // Chris@16: // Alternately, you can declare the loop variable first, Chris@16: // so you can access it after the loop finishes. Obviously, Chris@16: // if you do it this way, then the loop variable cannot be Chris@16: // a reference. Chris@16: // Chris@16: // int i; Chris@16: // BOOST_FOREACH(i, int_list) Chris@16: // { ... } Chris@16: // Chris@16: #define BOOST_FOREACH(VAR, COL) \ Chris@16: BOOST_FOREACH_PREAMBLE() \ Chris@16: if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_col) = BOOST_FOREACH_CONTAIN(COL)) {} else \ Chris@16: if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_cur) = BOOST_FOREACH_BEGIN(COL)) {} else \ Chris@16: if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_end) = BOOST_FOREACH_END(COL)) {} else \ Chris@16: for (bool BOOST_FOREACH_ID(_foreach_continue) = true; \ Chris@16: BOOST_FOREACH_ID(_foreach_continue) && !BOOST_FOREACH_DONE(COL); \ Chris@16: BOOST_FOREACH_ID(_foreach_continue) ? BOOST_FOREACH_NEXT(COL) : (void)0) \ Chris@16: if (boost::foreach_detail_::set_false(BOOST_FOREACH_ID(_foreach_continue))) {} else \ Chris@16: for (VAR = BOOST_FOREACH_DEREF(COL); !BOOST_FOREACH_ID(_foreach_continue); BOOST_FOREACH_ID(_foreach_continue) = true) Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // BOOST_REVERSE_FOREACH Chris@16: // Chris@16: // For iterating over collections in reverse order. In Chris@16: // all other respects, BOOST_REVERSE_FOREACH is like Chris@16: // BOOST_FOREACH. Chris@16: // Chris@16: #define BOOST_REVERSE_FOREACH(VAR, COL) \ Chris@16: BOOST_FOREACH_PREAMBLE() \ Chris@16: if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_col) = BOOST_FOREACH_CONTAIN(COL)) {} else \ Chris@16: if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_cur) = BOOST_FOREACH_RBEGIN(COL)) {} else \ Chris@16: if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_end) = BOOST_FOREACH_REND(COL)) {} else \ Chris@16: for (bool BOOST_FOREACH_ID(_foreach_continue) = true; \ Chris@16: BOOST_FOREACH_ID(_foreach_continue) && !BOOST_FOREACH_RDONE(COL); \ Chris@16: BOOST_FOREACH_ID(_foreach_continue) ? BOOST_FOREACH_RNEXT(COL) : (void)0) \ Chris@16: if (boost::foreach_detail_::set_false(BOOST_FOREACH_ID(_foreach_continue))) {} else \ Chris@16: for (VAR = BOOST_FOREACH_RDEREF(COL); !BOOST_FOREACH_ID(_foreach_continue); BOOST_FOREACH_ID(_foreach_continue) = true) Chris@16: Chris@16: #endif