annotate DEPENDENCIES/generic/include/boost/foreach.hpp @ 125:34e428693f5d vext

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