os/ossrv/ossrv_pub/boost_apis/boost/foreach.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/foreach.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,812 @@
     1.4 +///////////////////////////////////////////////////////////////////////////////
     1.5 +// foreach.hpp header file
     1.6 +//
     1.7 +// Copyright 2004 Eric Niebler.
     1.8 +// Distributed under the Boost Software License, Version 1.0. (See
     1.9 +// accompanying file LICENSE_1_0.txt or copy at
    1.10 +// http://www.boost.org/LICENSE_1_0.txt)
    1.11 +//
    1.12 +// Credits:
    1.13 +//  Anson Tsao        - for the initial inspiration and several good suggestions.
    1.14 +//  Thorsten Ottosen  - for Boost.Range, and for suggesting a way to detect
    1.15 +//                      const-qualified rvalues at compile time on VC7.1+
    1.16 +//  Russell Hind      - For help porting to Borland
    1.17 +//  Alisdair Meredith - For help porting to Borland
    1.18 +//  Stefan Slapeta    - For help porting to Intel
    1.19 +
    1.20 +#ifndef BOOST_FOREACH
    1.21 +
    1.22 +// MS compatible compilers support #pragma once
    1.23 +#if defined(_MSC_VER) && (_MSC_VER >= 1020)
    1.24 +# pragma once
    1.25 +#endif
    1.26 +
    1.27 +#include <cstddef>
    1.28 +#include <utility>  // for std::pair
    1.29 +
    1.30 +#include <boost/config.hpp>
    1.31 +#include <boost/detail/workaround.hpp>
    1.32 +
    1.33 +// Some compilers let us detect even const-qualified rvalues at compile-time
    1.34 +#if BOOST_WORKAROUND(BOOST_MSVC, >= 1310)                                                       \
    1.35 + || (BOOST_WORKAROUND(__GNUC__, >= 4) && !defined(BOOST_INTEL))                                 \
    1.36 + || (BOOST_WORKAROUND(__GNUC__, == 3) && (__GNUC_MINOR__ >= 4) && !defined(BOOST_INTEL))
    1.37 +# define BOOST_FOREACH_COMPILE_TIME_CONST_RVALUE_DETECTION
    1.38 +#else
    1.39 +// Some compilers allow temporaries to be bound to non-const references.
    1.40 +// These compilers make it impossible to for BOOST_FOREACH to detect
    1.41 +// temporaries and avoid reevaluation of the collection expression.
    1.42 +# if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)                                                      \
    1.43 +  || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))                                     \
    1.44 +  || (BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 700) && defined(_MSC_VER))                   \
    1.45 +  || BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x570))                                      \
    1.46 +  || BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(60590042))
    1.47 +#  define BOOST_FOREACH_NO_RVALUE_DETECTION
    1.48 +# endif
    1.49 +// Some compilers do not correctly implement the lvalue/rvalue conversion
    1.50 +// rules of the ternary conditional operator.
    1.51 +# if defined(BOOST_FOREACH_NO_RVALUE_DETECTION)                                                 \
    1.52 +  || defined(BOOST_NO_SFINAE)                                                                   \
    1.53 +  || BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1400))                                        \
    1.54 +  || BOOST_WORKAROUND(BOOST_INTEL_WIN, <= 810)                                                  \
    1.55 +  || BOOST_WORKAROUND(__GNUC__, < 3)                                                            \
    1.56 +  || (BOOST_WORKAROUND(__GNUC__, == 3) && (__GNUC_MINOR__ <= 2))                                \
    1.57 +  || (BOOST_WORKAROUND(__GNUC__, == 3) && (__GNUC_MINOR__ <= 3) && defined(__APPLE_CC__))       \
    1.58 +  || BOOST_WORKAROUND(__IBMCPP__, BOOST_TESTED_AT(600))                                         \
    1.59 +  || BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206))
    1.60 +#  define BOOST_FOREACH_NO_CONST_RVALUE_DETECTION
    1.61 +# else
    1.62 +#  define BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION
    1.63 +# endif
    1.64 +#endif
    1.65 +
    1.66 +#include <boost/mpl/if.hpp>
    1.67 +#include <boost/mpl/logical.hpp>
    1.68 +#include <boost/mpl/eval_if.hpp>
    1.69 +#include <boost/noncopyable.hpp>
    1.70 +#include <boost/range/end.hpp>
    1.71 +#include <boost/range/begin.hpp>
    1.72 +#include <boost/range/result_iterator.hpp>
    1.73 +#include <boost/type_traits/is_array.hpp>
    1.74 +#include <boost/type_traits/is_const.hpp>
    1.75 +#include <boost/type_traits/is_abstract.hpp>
    1.76 +#include <boost/type_traits/is_base_and_derived.hpp>
    1.77 +#include <boost/iterator/iterator_traits.hpp>
    1.78 +#include <boost/utility/addressof.hpp>
    1.79 +
    1.80 +#ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION
    1.81 +# include <new>
    1.82 +# include <boost/aligned_storage.hpp>
    1.83 +# include <boost/utility/enable_if.hpp>
    1.84 +# include <boost/type_traits/remove_const.hpp>
    1.85 +#endif
    1.86 +
    1.87 +// This must be at global scope, hence the uglified name
    1.88 +enum boost_foreach_argument_dependent_lookup_hack
    1.89 +{
    1.90 +    boost_foreach_argument_dependent_lookup_hack_value
    1.91 +};
    1.92 +
    1.93 +namespace boost
    1.94 +{
    1.95 +
    1.96 +// forward declarations for iterator_range
    1.97 +template<typename T>
    1.98 +class iterator_range;
    1.99 +
   1.100 +// forward declarations for sub_range
   1.101 +template<typename T>
   1.102 +class sub_range;
   1.103 +
   1.104 +namespace foreach
   1.105 +{
   1.106 +    ///////////////////////////////////////////////////////////////////////////////
   1.107 +    // in_range
   1.108 +    //
   1.109 +    template<typename T>
   1.110 +    inline std::pair<T, T> in_range(T begin, T end)
   1.111 +    {
   1.112 +        return std::make_pair(begin, end);
   1.113 +    }
   1.114 +
   1.115 +    ///////////////////////////////////////////////////////////////////////////////
   1.116 +    // boost::foreach::tag
   1.117 +    //
   1.118 +    typedef boost_foreach_argument_dependent_lookup_hack tag;
   1.119 +
   1.120 +    ///////////////////////////////////////////////////////////////////////////////
   1.121 +    // boost::foreach::is_lightweight_proxy
   1.122 +    //   Specialize this for user-defined collection types if they are inexpensive to copy.
   1.123 +    //   This tells BOOST_FOREACH it can avoid the rvalue/lvalue detection stuff.
   1.124 +    template<typename T>
   1.125 +    struct is_lightweight_proxy
   1.126 +      : boost::mpl::false_
   1.127 +    {
   1.128 +    };
   1.129 +
   1.130 +    ///////////////////////////////////////////////////////////////////////////////
   1.131 +    // boost::foreach::is_noncopyable
   1.132 +    //   Specialize this for user-defined collection types if they cannot be copied.
   1.133 +    //   This also tells BOOST_FOREACH to avoid the rvalue/lvalue detection stuff.
   1.134 +    template<typename T>
   1.135 +    struct is_noncopyable
   1.136 +    #if !defined(BOOST_BROKEN_IS_BASE_AND_DERIVED) && !defined(BOOST_NO_IS_ABSTRACT)
   1.137 +      : boost::mpl::or_<
   1.138 +            boost::is_abstract<T>
   1.139 +          , boost::is_base_and_derived<boost::noncopyable, T>
   1.140 +        >
   1.141 +    #elif !defined(BOOST_BROKEN_IS_BASE_AND_DERIVED)
   1.142 +      : boost::is_base_and_derived<boost::noncopyable, T>
   1.143 +    #elif !defined(BOOST_NO_IS_ABSTRACT)
   1.144 +      : boost::is_abstract<T>
   1.145 +    #else
   1.146 +      : boost::mpl::false_
   1.147 +    #endif
   1.148 +    {
   1.149 +    };
   1.150 +
   1.151 +} // namespace foreach
   1.152 +
   1.153 +} // namespace boost
   1.154 +
   1.155 +// vc6/7 needs help ordering the following overloads
   1.156 +#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
   1.157 +# define BOOST_FOREACH_TAG_DEFAULT ...
   1.158 +#else
   1.159 +# define BOOST_FOREACH_TAG_DEFAULT boost::foreach::tag
   1.160 +#endif
   1.161 +
   1.162 +///////////////////////////////////////////////////////////////////////////////
   1.163 +// boost_foreach_is_lightweight_proxy
   1.164 +//   Another customization point for the is_lightweight_proxy optimization,
   1.165 +//   this one works on legacy compilers. Overload boost_foreach_is_lightweight_proxy
   1.166 +//   at the global namespace for your type.
   1.167 +template<typename T>
   1.168 +inline boost::foreach::is_lightweight_proxy<T> *
   1.169 +boost_foreach_is_lightweight_proxy(T *&, BOOST_FOREACH_TAG_DEFAULT) { return 0; }
   1.170 +
   1.171 +template<typename T>
   1.172 +inline boost::mpl::true_ *
   1.173 +boost_foreach_is_lightweight_proxy(std::pair<T, T> *&, boost::foreach::tag) { return 0; }
   1.174 +
   1.175 +template<typename T>
   1.176 +inline boost::mpl::true_ *
   1.177 +boost_foreach_is_lightweight_proxy(boost::iterator_range<T> *&, boost::foreach::tag) { return 0; }
   1.178 +
   1.179 +template<typename T>
   1.180 +inline boost::mpl::true_ *
   1.181 +boost_foreach_is_lightweight_proxy(boost::sub_range<T> *&, boost::foreach::tag) { return 0; }
   1.182 +
   1.183 +template<typename T>
   1.184 +inline boost::mpl::true_ *
   1.185 +boost_foreach_is_lightweight_proxy(T **&, boost::foreach::tag) { return 0; }
   1.186 +
   1.187 +///////////////////////////////////////////////////////////////////////////////
   1.188 +// boost_foreach_is_noncopyable
   1.189 +//   Another customization point for the is_noncopyable trait,
   1.190 +//   this one works on legacy compilers. Overload boost_foreach_is_noncopyable
   1.191 +//   at the global namespace for your type.
   1.192 +template<typename T>
   1.193 +inline boost::foreach::is_noncopyable<T> *
   1.194 +boost_foreach_is_noncopyable(T *&, BOOST_FOREACH_TAG_DEFAULT) { return 0; }
   1.195 +
   1.196 +namespace boost
   1.197 +{
   1.198 +
   1.199 +namespace foreach_detail_
   1.200 +{
   1.201 +
   1.202 +///////////////////////////////////////////////////////////////////////////////
   1.203 +// Define some utilities for assessing the properties of expressions
   1.204 +//
   1.205 +typedef char yes_type;
   1.206 +typedef char (&no_type)[2];
   1.207 +yes_type is_true(boost::mpl::true_ *);
   1.208 +no_type is_true(boost::mpl::false_ *);
   1.209 +
   1.210 +// Extracts the desired property from the expression without evaluating it
   1.211 +#define BOOST_FOREACH_PROTECT(expr)                                                             \
   1.212 +    (static_cast<boost::mpl::bool_<1 == sizeof(boost::foreach_detail_::is_true(expr))> *>(0))
   1.213 +
   1.214 +template<typename Bool1, typename Bool2>
   1.215 +inline boost::mpl::and_<Bool1, Bool2> *and_(Bool1 *, Bool2 *) { return 0; }
   1.216 +
   1.217 +template<typename Bool1, typename Bool2, typename Bool3>
   1.218 +inline boost::mpl::and_<Bool1, Bool2, Bool3> *and_(Bool1 *, Bool2 *, Bool3 *) { return 0; }
   1.219 +
   1.220 +template<typename Bool1, typename Bool2>
   1.221 +inline boost::mpl::or_<Bool1, Bool2> *or_(Bool1 *, Bool2 *) { return 0; }
   1.222 +
   1.223 +template<typename Bool1, typename Bool2, typename Bool3>
   1.224 +inline boost::mpl::or_<Bool1, Bool2, Bool3> *or_(Bool1 *, Bool2 *, Bool3 *) { return 0; }
   1.225 +
   1.226 +template<typename Bool>
   1.227 +inline boost::mpl::not_<Bool> *not_(Bool *) { return 0; }
   1.228 +
   1.229 +template<typename T>
   1.230 +inline boost::mpl::false_ *is_rvalue_(T &, int) { return 0; }
   1.231 +
   1.232 +template<typename T>
   1.233 +inline boost::mpl::true_ *is_rvalue_(T const &, ...) { return 0; }
   1.234 +
   1.235 +template<typename T>
   1.236 +inline boost::is_array<T> *is_array_(T const &) { return 0; }
   1.237 +
   1.238 +template<typename T>
   1.239 +inline boost::is_const<T> *is_const_(T &) { return 0; }
   1.240 +
   1.241 +#ifndef BOOST_FOREACH_NO_RVALUE_DETECTION
   1.242 +template<typename T>
   1.243 +inline boost::mpl::true_ *is_const_(T const &) { return 0; }
   1.244 +#endif
   1.245 +
   1.246 +///////////////////////////////////////////////////////////////////////////////
   1.247 +// auto_any_t/auto_any
   1.248 +//  General utility for putting an object of any type into automatic storage
   1.249 +struct auto_any_base
   1.250 +{
   1.251 +    // auto_any_base must evaluate to false in boolean context so that
   1.252 +    // they can be declared in if() statements.
   1.253 +    operator bool() const
   1.254 +    {
   1.255 +        return false;
   1.256 +    }
   1.257 +};
   1.258 +
   1.259 +template<typename T>
   1.260 +struct auto_any : auto_any_base
   1.261 +{
   1.262 +    auto_any(T const &t)
   1.263 +      : item(t)
   1.264 +    {
   1.265 +    }
   1.266 +
   1.267 +    // temporaries of type auto_any will be bound to const auto_any_base
   1.268 +    // references, but we still want to be able to mutate the stored
   1.269 +    // data, so declare it as mutable.
   1.270 +    mutable T item;
   1.271 +};
   1.272 +
   1.273 +typedef auto_any_base const &auto_any_t;
   1.274 +
   1.275 +template<typename T, typename C>
   1.276 +inline BOOST_DEDUCED_TYPENAME boost::mpl::if_<C, T const, T>::type &auto_any_cast(auto_any_t a)
   1.277 +{
   1.278 +    return static_cast<auto_any<T> const &>(a).item;
   1.279 +}
   1.280 +
   1.281 +typedef boost::mpl::true_ const_;
   1.282 +
   1.283 +///////////////////////////////////////////////////////////////////////////////
   1.284 +// type2type
   1.285 +//
   1.286 +template<typename T, typename C = boost::mpl::false_>
   1.287 +struct type2type
   1.288 +  : boost::mpl::if_<C, T const, T>
   1.289 +{
   1.290 +};
   1.291 +
   1.292 +template<typename T, typename C = boost::mpl::false_>
   1.293 +struct foreach_iterator
   1.294 +{
   1.295 +    typedef BOOST_DEDUCED_TYPENAME boost::mpl::eval_if<
   1.296 +        C
   1.297 +      , range_const_iterator<T>
   1.298 +      , range_iterator<T>
   1.299 +    >::type type;
   1.300 +};
   1.301 +
   1.302 +template<typename T, typename C = boost::mpl::false_>
   1.303 +struct foreach_reference
   1.304 +  : iterator_reference<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>
   1.305 +{
   1.306 +};
   1.307 +
   1.308 +///////////////////////////////////////////////////////////////////////////////
   1.309 +// encode_type
   1.310 +//
   1.311 +template<typename T>
   1.312 +inline type2type<T> *encode_type(T &, boost::mpl::false_ *) { return 0; }
   1.313 +
   1.314 +template<typename T>
   1.315 +inline type2type<T, const_> *encode_type(T const &, boost::mpl::true_ *) { return 0; }
   1.316 +
   1.317 +///////////////////////////////////////////////////////////////////////////////
   1.318 +// set_false
   1.319 +//
   1.320 +inline bool set_false(bool &b) { return b = false; }
   1.321 +
   1.322 +///////////////////////////////////////////////////////////////////////////////
   1.323 +// to_ptr
   1.324 +//
   1.325 +template<typename T>
   1.326 +inline T *&to_ptr(T const &)
   1.327 +{
   1.328 +    static T *t = 0;
   1.329 +    return t;
   1.330 +}
   1.331 +
   1.332 +// Borland needs a little extra help with arrays
   1.333 +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
   1.334 +template<typename T,std::size_t N>
   1.335 +inline T (*&to_ptr(T (&)[N]))[N]
   1.336 +{
   1.337 +    static T (*t)[N] = 0;
   1.338 +    return t;
   1.339 +}
   1.340 +#endif
   1.341 +
   1.342 +///////////////////////////////////////////////////////////////////////////////
   1.343 +// derefof
   1.344 +//
   1.345 +template<typename T>
   1.346 +inline T &derefof(T *t)
   1.347 +{
   1.348 +    // This is a work-around for a compiler bug in Borland. If T* is a pointer to array type U(*)[N],
   1.349 +    // then dereferencing it results in a U* instead of U(&)[N]. The cast forces the issue.
   1.350 +    return reinterpret_cast<T &>(
   1.351 +        *const_cast<char *>(
   1.352 +            reinterpret_cast<char const volatile *>(t)
   1.353 +        )
   1.354 +    );
   1.355 +}
   1.356 +
   1.357 +#ifdef BOOST_FOREACH_COMPILE_TIME_CONST_RVALUE_DETECTION
   1.358 +///////////////////////////////////////////////////////////////////////////////
   1.359 +// Detect at compile-time whether an expression yields an rvalue or
   1.360 +// an lvalue. This is rather non-standard, but some popular compilers
   1.361 +// accept it.
   1.362 +///////////////////////////////////////////////////////////////////////////////
   1.363 +
   1.364 +///////////////////////////////////////////////////////////////////////////////
   1.365 +// rvalue_probe
   1.366 +//
   1.367 +template<typename T>
   1.368 +struct rvalue_probe
   1.369 +{
   1.370 +    struct private_type_ {};
   1.371 +    // can't ever return an array by value
   1.372 +    typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_<
   1.373 +        boost::mpl::or_<boost::is_abstract<T>, boost::is_array<T> >, private_type_, T
   1.374 +    >::type value_type;
   1.375 +    operator value_type();
   1.376 +    operator T &() const;
   1.377 +};
   1.378 +
   1.379 +template<typename T>
   1.380 +rvalue_probe<T> const make_probe(T const &t);
   1.381 +
   1.382 +# define BOOST_FOREACH_IS_RVALUE(COL)                                                           \
   1.383 +    boost::foreach_detail_::and_(                                                               \
   1.384 +        boost::foreach_detail_::not_(boost::foreach_detail_::is_array_(COL))                    \
   1.385 +      , BOOST_FOREACH_PROTECT(boost::foreach_detail_::is_rvalue_(                               \
   1.386 +            (true ? boost::foreach_detail_::make_probe(COL) : (COL)), 0)))
   1.387 +
   1.388 +#elif defined(BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION)
   1.389 +///////////////////////////////////////////////////////////////////////////////
   1.390 +// Detect at run-time whether an expression yields an rvalue
   1.391 +// or an lvalue. This is 100% standard C++, but not all compilers
   1.392 +// accept it. Also, it causes FOREACH to break when used with non-
   1.393 +// copyable collection types.
   1.394 +///////////////////////////////////////////////////////////////////////////////
   1.395 +
   1.396 +///////////////////////////////////////////////////////////////////////////////
   1.397 +// rvalue_probe
   1.398 +//
   1.399 +template<typename T>
   1.400 +struct rvalue_probe
   1.401 +{
   1.402 +    rvalue_probe(T &t, bool &b)
   1.403 +      : value(t)
   1.404 +      , is_rvalue(b)
   1.405 +    {
   1.406 +    }
   1.407 +
   1.408 +    struct private_type_ {};
   1.409 +    // can't ever return an array or an abstract type by value
   1.410 +    #ifdef BOOST_NO_IS_ABSTRACT
   1.411 +    typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_<
   1.412 +        boost::is_array<T>, private_type_, T
   1.413 +    >::type value_type;
   1.414 +    #else
   1.415 +    typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_<
   1.416 +        boost::mpl::or_<boost::is_abstract<T>, boost::is_array<T> >, private_type_, T
   1.417 +    >::type value_type;
   1.418 +    #endif
   1.419 +    
   1.420 +    operator value_type()
   1.421 +    {
   1.422 +        this->is_rvalue = true;
   1.423 +        return this->value;
   1.424 +    }
   1.425 +
   1.426 +    operator T &() const
   1.427 +    {
   1.428 +        return this->value;
   1.429 +    }
   1.430 +
   1.431 +private:
   1.432 +    T &value;
   1.433 +    bool &is_rvalue;
   1.434 +};
   1.435 +
   1.436 +template<typename T>
   1.437 +rvalue_probe<T> make_probe(T &t, bool &b) { return rvalue_probe<T>(t, b); }
   1.438 +
   1.439 +template<typename T>
   1.440 +rvalue_probe<T const> make_probe(T const &t, bool &b)  { return rvalue_probe<T const>(t, b); }
   1.441 +
   1.442 +///////////////////////////////////////////////////////////////////////////////
   1.443 +// simple_variant
   1.444 +//  holds either a T or a T const*
   1.445 +template<typename T>
   1.446 +struct simple_variant
   1.447 +{
   1.448 +    simple_variant(T const *t)
   1.449 +      : is_rvalue(false)
   1.450 +    {
   1.451 +        *static_cast<T const **>(this->data.address()) = t;
   1.452 +    }
   1.453 +
   1.454 +    simple_variant(T const &t)
   1.455 +      : is_rvalue(true)
   1.456 +    {
   1.457 +        ::new(this->data.address()) T(t);
   1.458 +    }
   1.459 +
   1.460 +    simple_variant(simple_variant const &that)
   1.461 +      : is_rvalue(that.is_rvalue)
   1.462 +    {
   1.463 +        if(this->is_rvalue)
   1.464 +            ::new(this->data.address()) T(*that.get());
   1.465 +        else
   1.466 +            *static_cast<T const **>(this->data.address()) = that.get();
   1.467 +    }
   1.468 +
   1.469 +    ~simple_variant()
   1.470 +    {
   1.471 +        if(this->is_rvalue)
   1.472 +            this->get()->~T();
   1.473 +    }
   1.474 +
   1.475 +    T const *get() const
   1.476 +    {
   1.477 +        if(this->is_rvalue)
   1.478 +            return static_cast<T const *>(this->data.address());
   1.479 +        else
   1.480 +            return *static_cast<T const * const *>(this->data.address());
   1.481 +    }
   1.482 +
   1.483 +private:
   1.484 +    enum size_type { size = sizeof(T) > sizeof(T*) ? sizeof(T) : sizeof(T*) };
   1.485 +    simple_variant &operator =(simple_variant const &); 
   1.486 +    bool const is_rvalue;
   1.487 +    aligned_storage<size> data;
   1.488 +};
   1.489 +
   1.490 +// If the collection is an array or is noncopyable, it must be an lvalue.
   1.491 +// If the collection is a lightweight proxy, treat it as an rvalue
   1.492 +// BUGBUG what about a noncopyable proxy?
   1.493 +template<typename LValue, typename IsProxy>
   1.494 +inline BOOST_DEDUCED_TYPENAME boost::enable_if<boost::mpl::or_<LValue, IsProxy>, IsProxy>::type *
   1.495 +should_copy_impl(LValue *, IsProxy *, bool *)
   1.496 +{
   1.497 +    return 0;
   1.498 +}
   1.499 +
   1.500 +// Otherwise, we must determine at runtime whether it's an lvalue or rvalue
   1.501 +inline bool *
   1.502 +should_copy_impl(boost::mpl::false_ *, boost::mpl::false_ *, bool *is_rvalue)
   1.503 +{
   1.504 +    return is_rvalue;
   1.505 +}
   1.506 +
   1.507 +#endif
   1.508 +
   1.509 +///////////////////////////////////////////////////////////////////////////////
   1.510 +// contain
   1.511 +//
   1.512 +template<typename T>
   1.513 +inline auto_any<T> contain(T const &t, boost::mpl::true_ *) // rvalue
   1.514 +{
   1.515 +    return t;
   1.516 +}
   1.517 +
   1.518 +template<typename T>
   1.519 +inline auto_any<T *> contain(T &t, boost::mpl::false_ *) // lvalue
   1.520 +{
   1.521 +    // Cannot seem to get sunpro to handle addressof() with array types.
   1.522 +    #if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x570))
   1.523 +    return &t;
   1.524 +    #else
   1.525 +    return boost::addressof(t);
   1.526 +    #endif
   1.527 +}
   1.528 +
   1.529 +#ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION
   1.530 +template<typename T>
   1.531 +auto_any<simple_variant<T> >
   1.532 +contain(T const &t, bool *rvalue)
   1.533 +{
   1.534 +    return *rvalue ? simple_variant<T>(t) : simple_variant<T>(&t);
   1.535 +}
   1.536 +#endif
   1.537 +
   1.538 +/////////////////////////////////////////////////////////////////////////////
   1.539 +// begin
   1.540 +//
   1.541 +template<typename T, typename C>
   1.542 +inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>
   1.543 +begin(auto_any_t col, type2type<T, C> *, boost::mpl::true_ *) // rvalue
   1.544 +{
   1.545 +    return boost::begin(auto_any_cast<T, C>(col));
   1.546 +}
   1.547 +
   1.548 +template<typename T, typename C>
   1.549 +inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>
   1.550 +begin(auto_any_t col, type2type<T, C> *, boost::mpl::false_ *) // lvalue
   1.551 +{
   1.552 +    typedef BOOST_DEDUCED_TYPENAME type2type<T, C>::type type;
   1.553 +    typedef BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type iterator;
   1.554 +    return iterator(boost::begin(derefof(auto_any_cast<type *, boost::mpl::false_>(col))));
   1.555 +}
   1.556 +
   1.557 +#ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION
   1.558 +template<typename T>
   1.559 +auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, const_>::type>
   1.560 +begin(auto_any_t col, type2type<T, const_> *, bool *)
   1.561 +{
   1.562 +    return boost::begin(*auto_any_cast<simple_variant<T>, boost::mpl::false_>(col).get());
   1.563 +}
   1.564 +#endif
   1.565 +
   1.566 +///////////////////////////////////////////////////////////////////////////////
   1.567 +// end
   1.568 +//
   1.569 +template<typename T, typename C>
   1.570 +inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>
   1.571 +end(auto_any_t col, type2type<T, C> *, boost::mpl::true_ *) // rvalue
   1.572 +{
   1.573 +    return boost::end(auto_any_cast<T, C>(col));
   1.574 +}
   1.575 +
   1.576 +template<typename T, typename C>
   1.577 +inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>
   1.578 +end(auto_any_t col, type2type<T, C> *, boost::mpl::false_ *) // lvalue
   1.579 +{
   1.580 +    typedef BOOST_DEDUCED_TYPENAME type2type<T, C>::type type;
   1.581 +    typedef BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type iterator;
   1.582 +    return iterator(boost::end(derefof(auto_any_cast<type *, boost::mpl::false_>(col))));
   1.583 +}
   1.584 +
   1.585 +#ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION
   1.586 +template<typename T>
   1.587 +auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, const_>::type>
   1.588 +end(auto_any_t col, type2type<T, const_> *, bool *)
   1.589 +{
   1.590 +    return boost::end(*auto_any_cast<simple_variant<T>, boost::mpl::false_>(col).get());
   1.591 +}
   1.592 +#endif
   1.593 +
   1.594 +#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
   1.595 +template<typename T, typename C>
   1.596 +inline auto_any<int>
   1.597 +end(auto_any_t col, type2type<T *, C> *, boost::mpl::true_ *) // null-terminated C-style strings
   1.598 +{
   1.599 +    return 0; // not used
   1.600 +}
   1.601 +#endif
   1.602 +
   1.603 +///////////////////////////////////////////////////////////////////////////////
   1.604 +// done
   1.605 +//
   1.606 +template<typename T, typename C>
   1.607 +inline bool done(auto_any_t cur, auto_any_t end, type2type<T, C> *)
   1.608 +{
   1.609 +    typedef BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type iter_t;
   1.610 +    return auto_any_cast<iter_t, boost::mpl::false_>(cur) == auto_any_cast<iter_t, boost::mpl::false_>(end);
   1.611 +}
   1.612 +
   1.613 +#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
   1.614 +template<typename T, typename C>
   1.615 +inline bool done(auto_any_t cur, auto_any_t, type2type<T *, C> *) // null-terminated C-style strings
   1.616 +{
   1.617 +    return ! *auto_any_cast<T *, boost::mpl::false_>(cur);
   1.618 +}
   1.619 +#endif
   1.620 +
   1.621 +///////////////////////////////////////////////////////////////////////////////
   1.622 +// next
   1.623 +//
   1.624 +template<typename T, typename C>
   1.625 +inline void next(auto_any_t cur, type2type<T, C> *)
   1.626 +{
   1.627 +    typedef BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type iter_t;
   1.628 +    ++auto_any_cast<iter_t, boost::mpl::false_>(cur);
   1.629 +}
   1.630 +
   1.631 +///////////////////////////////////////////////////////////////////////////////
   1.632 +// deref
   1.633 +//
   1.634 +template<typename T, typename C>
   1.635 +inline BOOST_DEDUCED_TYPENAME foreach_reference<T, C>::type
   1.636 +deref(auto_any_t cur, type2type<T, C> *)
   1.637 +{
   1.638 +    typedef BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type iter_t;
   1.639 +    return *auto_any_cast<iter_t, boost::mpl::false_>(cur);
   1.640 +}
   1.641 +
   1.642 +} // namespace foreach_detail_
   1.643 +} // namespace boost
   1.644 +
   1.645 +// A sneaky way to get the type of the collection without evaluating the expression
   1.646 +#define BOOST_FOREACH_TYPEOF(COL)                                                               \
   1.647 +    (true ? 0 : boost::foreach_detail_::encode_type(COL, boost::foreach_detail_::is_const_(COL)))
   1.648 +
   1.649 +// returns true_* if the type is noncopyable
   1.650 +#define BOOST_FOREACH_IS_NONCOPYABLE(COL)                                                       \
   1.651 +    boost_foreach_is_noncopyable(                                                               \
   1.652 +        boost::foreach_detail_::to_ptr(COL)                                                     \
   1.653 +      , boost_foreach_argument_dependent_lookup_hack_value)
   1.654 +
   1.655 +// returns true_* if the type is a lightweight proxy (and is not noncopyable)
   1.656 +#define BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(COL)                                                 \
   1.657 +    boost::foreach_detail_::and_(                                                               \
   1.658 +        boost::foreach_detail_::not_(BOOST_FOREACH_IS_NONCOPYABLE(COL))                         \
   1.659 +      , boost_foreach_is_lightweight_proxy(                                                     \
   1.660 +            boost::foreach_detail_::to_ptr(COL)                                                 \
   1.661 +          , boost_foreach_argument_dependent_lookup_hack_value))
   1.662 +
   1.663 +#ifdef BOOST_FOREACH_COMPILE_TIME_CONST_RVALUE_DETECTION
   1.664 +///////////////////////////////////////////////////////////////////////////////
   1.665 +// R-values and const R-values supported here with zero runtime overhead
   1.666 +///////////////////////////////////////////////////////////////////////////////
   1.667 +
   1.668 +// No variable is needed to track the rvalue-ness of the collection expression
   1.669 +# define BOOST_FOREACH_PREAMBLE()                                                               \
   1.670 +    /**/
   1.671 +
   1.672 +// Evaluate the collection expression
   1.673 +# define BOOST_FOREACH_EVALUATE(COL)                                                            \
   1.674 +    (COL)
   1.675 +
   1.676 +# define BOOST_FOREACH_SHOULD_COPY(COL)                                                         \
   1.677 +    (true ? 0 : boost::foreach_detail_::or_(                                                    \
   1.678 +        BOOST_FOREACH_IS_RVALUE(COL)                                                            \
   1.679 +      , BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(COL)))
   1.680 +
   1.681 +#elif defined(BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION)
   1.682 +///////////////////////////////////////////////////////////////////////////////
   1.683 +// R-values and const R-values supported here
   1.684 +///////////////////////////////////////////////////////////////////////////////
   1.685 +
   1.686 +// Declare a variable to track the rvalue-ness of the collection expression
   1.687 +# define BOOST_FOREACH_PREAMBLE()                                                               \
   1.688 +    if (bool _foreach_is_rvalue = false) {} else
   1.689 +
   1.690 +// Evaluate the collection expression, and detect if it is an lvalue or and rvalue
   1.691 +# define BOOST_FOREACH_EVALUATE(COL)                                                            \
   1.692 +    (true ? boost::foreach_detail_::make_probe((COL), _foreach_is_rvalue) : (COL))
   1.693 +
   1.694 +// The rvalue/lvalue-ness of the collection expression is determined dynamically, unless
   1.695 +// type type is an array or is noncopyable or is non-const, in which case we know it's an lvalue.
   1.696 +// If the type happens to be a lightweight proxy, always make a copy.
   1.697 +# define BOOST_FOREACH_SHOULD_COPY(COL)                                                         \
   1.698 +    (boost::foreach_detail_::should_copy_impl(                                                  \
   1.699 +        true ? 0 : boost::foreach_detail_::or_(                                                 \
   1.700 +            boost::foreach_detail_::is_array_(COL)                                              \
   1.701 +          , BOOST_FOREACH_IS_NONCOPYABLE(COL)                                                   \
   1.702 +          , boost::foreach_detail_::not_(boost::foreach_detail_::is_const_(COL)))               \
   1.703 +      , true ? 0 : BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(COL)                                      \
   1.704 +      , &_foreach_is_rvalue))
   1.705 +
   1.706 +#elif !defined(BOOST_FOREACH_NO_RVALUE_DETECTION)
   1.707 +///////////////////////////////////////////////////////////////////////////////
   1.708 +// R-values supported here, const R-values NOT supported here
   1.709 +///////////////////////////////////////////////////////////////////////////////
   1.710 +
   1.711 +// No variable is needed to track the rvalue-ness of the collection expression
   1.712 +# define BOOST_FOREACH_PREAMBLE()                                                               \
   1.713 +    /**/
   1.714 +
   1.715 +// Evaluate the collection expression
   1.716 +# define BOOST_FOREACH_EVALUATE(COL)                                                            \
   1.717 +    (COL)
   1.718 +
   1.719 +// Determine whether the collection expression is an lvalue or an rvalue.
   1.720 +// NOTE: this gets the answer wrong for const rvalues.
   1.721 +# define BOOST_FOREACH_SHOULD_COPY(COL)                                                         \
   1.722 +    (true ? 0 : boost::foreach_detail_::or_(                                                    \
   1.723 +        boost::foreach_detail_::is_rvalue_((COL), 0)                                            \
   1.724 +      , BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(COL)))
   1.725 +
   1.726 +#else
   1.727 +///////////////////////////////////////////////////////////////////////////////
   1.728 +// R-values NOT supported here
   1.729 +///////////////////////////////////////////////////////////////////////////////
   1.730 +
   1.731 +// No variable is needed to track the rvalue-ness of the collection expression
   1.732 +# define BOOST_FOREACH_PREAMBLE()                                                               \
   1.733 +    /**/
   1.734 +
   1.735 +// Evaluate the collection expression
   1.736 +# define BOOST_FOREACH_EVALUATE(COL)                                                            \
   1.737 +    (COL)
   1.738 +
   1.739 +// Can't use rvalues with BOOST_FOREACH (unless they are lightweight proxies)
   1.740 +# define BOOST_FOREACH_SHOULD_COPY(COL)                                                         \
   1.741 +    (true ? 0 : BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(COL))
   1.742 +
   1.743 +#endif
   1.744 +
   1.745 +#define BOOST_FOREACH_CONTAIN(COL)                                                              \
   1.746 +    boost::foreach_detail_::contain(                                                            \
   1.747 +        BOOST_FOREACH_EVALUATE(COL)                                                             \
   1.748 +      , BOOST_FOREACH_SHOULD_COPY(COL))
   1.749 +
   1.750 +#define BOOST_FOREACH_BEGIN(COL)                                                                \
   1.751 +    boost::foreach_detail_::begin(                                                              \
   1.752 +        _foreach_col                                                                            \
   1.753 +      , BOOST_FOREACH_TYPEOF(COL)                                                               \
   1.754 +      , BOOST_FOREACH_SHOULD_COPY(COL))
   1.755 +
   1.756 +#define BOOST_FOREACH_END(COL)                                                                  \
   1.757 +    boost::foreach_detail_::end(                                                                \
   1.758 +        _foreach_col                                                                            \
   1.759 +      , BOOST_FOREACH_TYPEOF(COL)                                                               \
   1.760 +      , BOOST_FOREACH_SHOULD_COPY(COL))
   1.761 +
   1.762 +#define BOOST_FOREACH_DONE(COL)                                                                 \
   1.763 +    boost::foreach_detail_::done(                                                               \
   1.764 +        _foreach_cur                                                                            \
   1.765 +      , _foreach_end                                                                            \
   1.766 +      , BOOST_FOREACH_TYPEOF(COL))
   1.767 +
   1.768 +#define BOOST_FOREACH_NEXT(COL)                                                                 \
   1.769 +    boost::foreach_detail_::next(                                                               \
   1.770 +        _foreach_cur                                                                            \
   1.771 +      , BOOST_FOREACH_TYPEOF(COL))
   1.772 +
   1.773 +#define BOOST_FOREACH_DEREF(COL)                                                                \
   1.774 +    boost::foreach_detail_::deref(                                                              \
   1.775 +        _foreach_cur                                                                            \
   1.776 +      , BOOST_FOREACH_TYPEOF(COL))
   1.777 +
   1.778 +///////////////////////////////////////////////////////////////////////////////
   1.779 +// BOOST_FOREACH
   1.780 +//
   1.781 +//   For iterating over collections. Collections can be
   1.782 +//   arrays, null-terminated strings, or STL containers.
   1.783 +//   The loop variable can be a value or reference. For
   1.784 +//   example:
   1.785 +//
   1.786 +//   std::list<int> int_list(/*stuff*/);
   1.787 +//   BOOST_FOREACH(int &i, int_list)
   1.788 +//   {
   1.789 +//       /* 
   1.790 +//        * loop body goes here.
   1.791 +//        * i is a reference to the int in int_list.
   1.792 +//        */
   1.793 +//   }
   1.794 +//
   1.795 +//   Alternately, you can declare the loop variable first,
   1.796 +//   so you can access it after the loop finishes. Obviously,
   1.797 +//   if you do it this way, then the loop variable cannot be
   1.798 +//   a reference.
   1.799 +//
   1.800 +//   int i;
   1.801 +//   BOOST_FOREACH(i, int_list)
   1.802 +//       { ... }
   1.803 +//
   1.804 +#define BOOST_FOREACH(VAR, COL)                                                                 \
   1.805 +    BOOST_FOREACH_PREAMBLE()                                                                    \
   1.806 +    if (boost::foreach_detail_::auto_any_t _foreach_col = BOOST_FOREACH_CONTAIN(COL)) {} else   \
   1.807 +    if (boost::foreach_detail_::auto_any_t _foreach_cur = BOOST_FOREACH_BEGIN(COL)) {} else     \
   1.808 +    if (boost::foreach_detail_::auto_any_t _foreach_end = BOOST_FOREACH_END(COL)) {} else       \
   1.809 +    for (bool _foreach_continue = true;                                                         \
   1.810 +              _foreach_continue && !BOOST_FOREACH_DONE(COL);                                    \
   1.811 +              _foreach_continue ? BOOST_FOREACH_NEXT(COL) : (void)0)                            \
   1.812 +        if  (boost::foreach_detail_::set_false(_foreach_continue)) {} else                      \
   1.813 +        for (VAR = BOOST_FOREACH_DEREF(COL); !_foreach_continue; _foreach_continue = true)
   1.814 +
   1.815 +#endif