PageRenderTime 51ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/extlibs/headers/boost_1_51_0/boost/foreach.hpp

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