foreach.hpp 42 KB

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