PageRenderTime 65ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/boost_1_45_0/boost/foreach.hpp

https://bitbucket.org/Tank_Master/boost145
C++ Header | 1104 lines | 726 code | 145 blank | 233 comment | 64 complexity | a01394ed5cbdcbddbf70ded3ebb36ec1 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. #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. explicit 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 auto_any<T>(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 auto_any<T *>(&t);
  534. #else
  535. return auto_any<T *>(boost::addressof(t));
  536. #endif
  537. }
  538. #ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION
  539. template<typename T>
  540. inline auto_any<simple_variant<T> >
  541. contain(T const &t, bool *rvalue)
  542. {
  543. return auto_any<simple_variant<T> >(*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 auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>(
  554. boost::begin(auto_any_cast<T, C>(col)));
  555. }
  556. template<typename T, typename C>
  557. inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>
  558. begin(auto_any_t col, type2type<T, C> *, boost::mpl::false_ *) // lvalue
  559. {
  560. typedef BOOST_DEDUCED_TYPENAME type2type<T, C>::type type;
  561. typedef BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type iterator;
  562. return auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>(
  563. iterator(boost::begin(derefof(auto_any_cast<type *, boost::mpl::false_>(col)))));
  564. }
  565. #ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION
  566. template<typename T>
  567. inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, const_>::type>
  568. begin(auto_any_t col, type2type<T, const_> *, bool *)
  569. {
  570. return auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, const_>::type>(
  571. boost::begin(*auto_any_cast<simple_variant<T>, boost::mpl::false_>(col).get()));
  572. }
  573. #endif
  574. #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
  575. template<typename T, typename C>
  576. inline auto_any<T *>
  577. begin(auto_any_t col, type2type<T *, C> *, boost::mpl::true_ *) // null-terminated C-style strings
  578. {
  579. return auto_any<T *>(auto_any_cast<T *, boost::mpl::false_>(col));
  580. }
  581. #endif
  582. ///////////////////////////////////////////////////////////////////////////////
  583. // end
  584. //
  585. template<typename T, typename C>
  586. inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>
  587. end(auto_any_t col, type2type<T, C> *, boost::mpl::true_ *) // rvalue
  588. {
  589. return auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>(
  590. boost::end(auto_any_cast<T, C>(col)));
  591. }
  592. template<typename T, typename C>
  593. inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>
  594. end(auto_any_t col, type2type<T, C> *, boost::mpl::false_ *) // lvalue
  595. {
  596. typedef BOOST_DEDUCED_TYPENAME type2type<T, C>::type type;
  597. typedef BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type iterator;
  598. return auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>(
  599. iterator(boost::end(derefof(auto_any_cast<type *, boost::mpl::false_>(col)))));
  600. }
  601. #ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION
  602. template<typename T>
  603. inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, const_>::type>
  604. end(auto_any_t col, type2type<T, const_> *, bool *)
  605. {
  606. return auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, const_>::type>(
  607. boost::end(*auto_any_cast<simple_variant<T>, boost::mpl::false_>(col).get()));
  608. }
  609. #endif
  610. #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
  611. template<typename T, typename C>
  612. inline auto_any<int>
  613. end(auto_any_t, type2type<T *, C> *, boost::mpl::true_ *) // null-terminated C-style strings
  614. {
  615. return auto_any<int>(0); // not used
  616. }
  617. #endif
  618. ///////////////////////////////////////////////////////////////////////////////
  619. // done
  620. //
  621. template<typename T, typename C>
  622. inline bool done(auto_any_t cur, auto_any_t end, type2type<T, C> *)
  623. {
  624. typedef BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type iter_t;
  625. return auto_any_cast<iter_t, boost::mpl::false_>(cur) == auto_any_cast<iter_t, boost::mpl::false_>(end);
  626. }
  627. #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
  628. template<typename T, typename C>
  629. inline bool done(auto_any_t cur, auto_any_t, type2type<T *, C> *) // null-terminated C-style strings
  630. {
  631. return ! *auto_any_cast<T *, boost::mpl::false_>(cur);
  632. }
  633. #endif
  634. ///////////////////////////////////////////////////////////////////////////////
  635. // next
  636. //
  637. template<typename T, typename C>
  638. inline void next(auto_any_t cur, type2type<T, C> *)
  639. {
  640. typedef BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type iter_t;
  641. ++auto_any_cast<iter_t, boost::mpl::false_>(cur);
  642. }
  643. ///////////////////////////////////////////////////////////////////////////////
  644. // deref
  645. //
  646. template<typename T, typename C>
  647. inline BOOST_DEDUCED_TYPENAME foreach_reference<T, C>::type
  648. deref(auto_any_t cur, type2type<T, C> *)
  649. {
  650. typedef BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type iter_t;
  651. return *auto_any_cast<iter_t, boost::mpl::false_>(cur);
  652. }
  653. /////////////////////////////////////////////////////////////////////////////
  654. // rbegin
  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::true_ *) // rvalue
  659. {
  660. return auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type>(
  661. boost::rbegin(auto_any_cast<T, C>(col)));
  662. }
  663. template<typename T, typename C>
  664. inline auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type>
  665. rbegin(auto_any_t col, type2type<T, C> *, boost::mpl::false_ *) // lvalue
  666. {
  667. typedef BOOST_DEDUCED_TYPENAME type2type<T, C>::type type;
  668. typedef BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type iterator;
  669. return auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type>(
  670. iterator(boost::rbegin(derefof(auto_any_cast<type *, boost::mpl::false_>(col)))));
  671. }
  672. #ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION
  673. template<typename T>
  674. inline auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, const_>::type>
  675. rbegin(auto_any_t col, type2type<T, const_> *, bool *)
  676. {
  677. return auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, const_>::type>(
  678. boost::rbegin(*auto_any_cast<simple_variant<T>, boost::mpl::false_>(col).get()));
  679. }
  680. #endif
  681. #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
  682. template<typename T, typename C>
  683. inline auto_any<reverse_iterator<T *> >
  684. rbegin(auto_any_t col, type2type<T *, C> *, boost::mpl::true_ *) // null-terminated C-style strings
  685. {
  686. T *p = auto_any_cast<T *, boost::mpl::false_>(col);
  687. while(0 != *p)
  688. ++p;
  689. return auto_any<reverse_iterator<T *> >(reverse_iterator<T *>(p));
  690. }
  691. #endif
  692. ///////////////////////////////////////////////////////////////////////////////
  693. // rend
  694. //
  695. template<typename T, typename C>
  696. inline auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type>
  697. rend(auto_any_t col, type2type<T, C> *, boost::mpl::true_ *) // rvalue
  698. {
  699. return auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type>(
  700. boost::rend(auto_any_cast<T, C>(col)));
  701. }
  702. template<typename T, typename C>
  703. inline auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type>
  704. rend(auto_any_t col, type2type<T, C> *, boost::mpl::false_ *) // lvalue
  705. {
  706. typedef BOOST_DEDUCED_TYPENAME type2type<T, C>::type type;
  707. typedef BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type iterator;
  708. return auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type>(
  709. iterator(boost::rend(derefof(auto_any_cast<type *, boost::mpl::false_>(col)))));
  710. }
  711. #ifdef BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION
  712. template<typename T>
  713. inline auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, const_>::type>
  714. rend(auto_any_t col, type2type<T, const_> *, bool *)
  715. {
  716. return auto_any<BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, const_>::type>(
  717. boost::rend(*auto_any_cast<simple_variant<T>, boost::mpl::false_>(col).get()));
  718. }
  719. #endif
  720. #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
  721. template<typename T, typename C>
  722. inline auto_any<reverse_iterator<T *> >
  723. rend(auto_any_t col, type2type<T *, C> *, boost::mpl::true_ *) // null-terminated C-style strings
  724. {
  725. return auto_any<reverse_iterator<T *> >(
  726. reverse_iterator<T *>(auto_any_cast<T *, boost::mpl::false_>(col)));
  727. }
  728. #endif
  729. ///////////////////////////////////////////////////////////////////////////////
  730. // rdone
  731. //
  732. template<typename T, typename C>
  733. inline bool rdone(auto_any_t cur, auto_any_t end, type2type<T, C> *)
  734. {
  735. typedef BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type iter_t;
  736. return auto_any_cast<iter_t, boost::mpl::false_>(cur) == auto_any_cast<iter_t, boost::mpl::false_>(end);
  737. }
  738. ///////////////////////////////////////////////////////////////////////////////
  739. // rnext
  740. //
  741. template<typename T, typename C>
  742. inline void rnext(auto_any_t cur, type2type<T, C> *)
  743. {
  744. typedef BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type iter_t;
  745. ++auto_any_cast<iter_t, boost::mpl::false_>(cur);
  746. }
  747. ///////////////////////////////////////////////////////////////////////////////
  748. // rderef
  749. //
  750. template<typename T, typename C>
  751. inline BOOST_DEDUCED_TYPENAME foreach_reference<T, C>::type
  752. rderef(auto_any_t cur, type2type<T, C> *)
  753. {
  754. typedef BOOST_DEDUCED_TYPENAME foreach_reverse_iterator<T, C>::type iter_t;
  755. return *auto_any_cast<iter_t, boost::mpl::false_>(cur);
  756. }
  757. } // namespace foreach_detail_
  758. } // namespace boost
  759. // Suppress a bogus code analysis warning on vc8+
  760. #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
  761. # define BOOST_FOREACH_SUPPRESS_WARNINGS() __pragma(warning(suppress:6001))
  762. #else
  763. # define BOOST_FOREACH_SUPPRESS_WARNINGS()
  764. #endif
  765. ///////////////////////////////////////////////////////////////////////////////
  766. // Define a macro for giving hidden variables a unique name. Not strictly
  767. // needed, but eliminates some warnings on some compilers.
  768. #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
  769. // With some versions of MSVC, use of __LINE__ to create unique identifiers
  770. // can fail when the Edit-and-Continue debug flag is used.
  771. # define BOOST_FOREACH_ID(x) x
  772. #else
  773. # define BOOST_FOREACH_ID(x) BOOST_PP_CAT(x, __LINE__)
  774. #endif
  775. // A sneaky way to get the type of the collection without evaluating the expression
  776. #define BOOST_FOREACH_TYPEOF(COL) \
  777. (true ? 0 : boost::foreach_detail_::encode_type(COL, boost::foreach_detail_::is_const_(COL)))
  778. // returns true_* if the type is noncopyable
  779. #define BOOST_FOREACH_IS_NONCOPYABLE(COL) \
  780. boost_foreach_is_noncopyable( \
  781. boost::foreach_detail_::to_ptr(COL) \
  782. , boost_foreach_argument_dependent_lookup_hack_value)
  783. // returns true_* if the type is a lightweight proxy (and is not noncopyable)
  784. #define BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(COL) \
  785. boost::foreach_detail_::and_( \
  786. boost::foreach_detail_::not_(BOOST_FOREACH_IS_NONCOPYABLE(COL)) \
  787. , boost_foreach_is_lightweight_proxy( \
  788. boost::foreach_detail_::to_ptr(COL) \
  789. , boost_foreach_argument_dependent_lookup_hack_value))
  790. #ifdef BOOST_FOREACH_COMPILE_TIME_CONST_RVALUE_DETECTION
  791. ///////////////////////////////////////////////////////////////////////////////
  792. // R-values and const R-values supported here with zero runtime overhead
  793. ///////////////////////////////////////////////////////////////////////////////
  794. // No variable is needed to track the rvalue-ness of the collection expression
  795. # define BOOST_FOREACH_PREAMBLE() \
  796. BOOST_FOREACH_SUPPRESS_WARNINGS()
  797. // Evaluate the collection expression
  798. # define BOOST_FOREACH_EVALUATE(COL) \
  799. (COL)
  800. # define BOOST_FOREACH_SHOULD_COPY(COL) \
  801. (true ? 0 : boost::foreach_detail_::or_( \
  802. BOOST_FOREACH_IS_RVALUE(COL) \
  803. , BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(COL)))
  804. #elif defined(BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION)
  805. ///////////////////////////////////////////////////////////////////////////////
  806. // R-values and const R-values supported here
  807. ///////////////////////////////////////////////////////////////////////////////
  808. // Declare a variable to track the rvalue-ness of the collection expression
  809. # define BOOST_FOREACH_PREAMBLE() \
  810. BOOST_FOREACH_SUPPRESS_WARNINGS() \
  811. if (bool BOOST_FOREACH_ID(_foreach_is_rvalue) = false) {} else
  812. // Evaluate the collection expression, and detect if it is an lvalue or and rvalue
  813. # define BOOST_FOREACH_EVALUATE(COL) \
  814. (true ? boost::foreach_detail_::make_probe((COL), BOOST_FOREACH_ID(_foreach_is_rvalue)) : (COL))
  815. // The rvalue/lvalue-ness of the collection expression is determined dynamically, unless
  816. // type type is an array or is noncopyable or is non-const, in which case we know it's an lvalue.
  817. // If the type happens to be a lightweight proxy, always make a copy.
  818. # define BOOST_FOREACH_SHOULD_COPY(COL) \
  819. (boost::foreach_detail_::should_copy_impl( \
  820. true ? 0 : boost::foreach_detail_::or_( \
  821. boost::foreach_detail_::is_array_(COL) \
  822. , BOOST_FOREACH_IS_NONCOPYABLE(COL) \
  823. , boost::foreach_detail_::not_(boost::foreach_detail_::is_const_(COL))) \
  824. , true ? 0 : BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(COL) \
  825. , &BOOST_FOREACH_ID(_foreach_is_rvalue)))
  826. #elif !defined(BOOST_FOREACH_NO_RVALUE_DETECTION)
  827. ///////////////////////////////////////////////////////////////////////////////
  828. // R-values supported here, const R-values NOT supported here
  829. ///////////////////////////////////////////////////////////////////////////////
  830. // No variable is needed to track the rvalue-ness of the collection expression
  831. # define BOOST_FOREACH_PREAMBLE() \
  832. BOOST_FOREACH_SUPPRESS_WARNINGS()
  833. // Evaluate the collection expression
  834. # define BOOST_FOREACH_EVALUATE(COL) \
  835. (COL)
  836. // Determine whether the collection expression is an lvalue or an rvalue.
  837. // NOTE: this gets the answer wrong for const rvalues.
  838. # define BOOST_FOREACH_SHOULD_COPY(COL) \
  839. (true ? 0 : boost::foreach_detail_::or_( \
  840. boost::foreach_detail_::is_rvalue_((COL), 0) \
  841. , BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(COL)))
  842. #else
  843. ///////////////////////////////////////////////////////////////////////////////
  844. // R-values NOT supported here
  845. ///////////////////////////////////////////////////////////////////////////////
  846. // No variable is needed to track the rvalue-ness of the collection expression
  847. # define BOOST_FOREACH_PREAMBLE() \
  848. BOOST_FOREACH_SUPPRESS_WARNINGS()
  849. // Evaluate the collection expression
  850. # define BOOST_FOREACH_EVALUATE(COL) \
  851. (COL)
  852. // Can't use rvalues with BOOST_FOREACH (unless they are lightweight proxies)
  853. # define BOOST_FOREACH_SHOULD_COPY(COL) \
  854. (true ? 0 : BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(COL))
  855. #endif
  856. #define BOOST_FOREACH_CONTAIN(COL) \
  857. boost::foreach_detail_::contain( \
  858. BOOST_FOREACH_EVALUATE(COL) \
  859. , BOOST_FOREACH_SHOULD_COPY(COL))
  860. #define BOOST_FOREACH_BEGIN(COL) \
  861. boost::foreach_detail_::begin( \
  862. BOOST_FOREACH_ID(_foreach_col) \
  863. , BOOST_FOREACH_TYPEOF(COL) \
  864. , BOOST_FOREACH_SHOULD_COPY(COL))
  865. #define BOOST_FOREACH_END(COL) \
  866. boost::foreach_detail_::end( \
  867. BOOST_FOREACH_ID(_foreach_col) \
  868. , BOOST_FOREACH_TYPEOF(COL) \
  869. , BOOST_FOREACH_SHOULD_COPY(COL))
  870. #define BOOST_FOREACH_DONE(COL) \
  871. boost::foreach_detail_::done( \
  872. BOOST_FOREACH_ID(_foreach_cur) \
  873. , BOOST_FOREACH_ID(_foreach_end) \
  874. , BOOST_FOREACH_TYPEOF(COL))
  875. #define BOOST_FOREACH_NEXT(COL) \
  876. boost::foreach_detail_::next( \
  877. BOOST_FOREACH_ID(_foreach_cur) \
  878. , BOOST_FOREACH_TYPEOF(COL))
  879. #define BOOST_FOREACH_DEREF(COL) \
  880. boost::foreach_detail_::deref( \
  881. BOOST_FOREACH_ID(_foreach_cur) \
  882. , BOOST_FOREACH_TYPEOF(COL))
  883. #define BOOST_FOREACH_RBEGIN(COL) \
  884. boost::foreach_detail_::rbegin( \
  885. BOOST_FOREACH_ID(_foreach_col) \
  886. , BOOST_FOREACH_TYPEOF(COL) \
  887. , BOOST_FOREACH_SHOULD_COPY(COL))
  888. #define BOOST_FOREACH_REND(COL) \
  889. boost::foreach_detail_::rend( \
  890. BOOST_FOREACH_ID(_foreach_col) \
  891. , BOOST_FOREACH_TYPEOF(COL) \
  892. , BOOST_FOREACH_SHOULD_COPY(COL))
  893. #define BOOST_FOREACH_RDONE(COL) \
  894. boost::foreach_detail_::rdone( \
  895. BOOST_FOREACH_ID(_foreach_cur) \
  896. , BOOST_FOREACH_ID(_foreach_end) \
  897. , BOOST_FOREACH_TYPEOF(COL))
  898. #define BOOST_FOREACH_RNEXT(COL) \
  899. boost::foreach_detail_::rnext( \
  900. BOOST_FOREACH_ID(_foreach_cur) \
  901. , BOOST_FOREACH_TYPEOF(COL))
  902. #define BOOST_FOREACH_RDEREF(COL) \
  903. boost::foreach_detail_::rderef( \
  904. BOOST_FOREACH_ID(_foreach_cur) \
  905. , BOOST_FOREACH_TYPEOF(COL))
  906. ///////////////////////////////////////////////////////////////////////////////
  907. // BOOST_FOREACH
  908. //
  909. // For iterating over collections. Collections can be
  910. // arrays, null-terminated strings, or STL containers.
  911. // The loop variable can be a value or reference. For
  912. // example:
  913. //
  914. // std::list<int> int_list(/*stuff*/);
  915. // BOOST_FOREACH(int &i, int_list)
  916. // {
  917. // /*
  918. // * loop body goes here.
  919. // * i is a reference to the int in int_list.
  920. // */
  921. // }
  922. //
  923. // Alternately, you can declare the loop variable first,
  924. // so you can access it after the loop finishes. Obviously,
  925. // if you do it this way, then the loop variable cannot be
  926. // a reference.
  927. //
  928. // int i;
  929. // BOOST_FOREACH(i, int_list)
  930. // { ... }
  931. //
  932. #define BOOST_FOREACH(VAR, COL) \
  933. BOOST_FOREACH_PREAMBLE() \
  934. if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_col) = BOOST_FOREACH_CONTAIN(COL)) {} else \
  935. if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_cur) = BOOST_FOREACH_BEGIN(COL)) {} else \
  936. if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_end) = BOOST_FOREACH_END(COL)) {} else \
  937. for (bool BOOST_FOREACH_ID(_foreach_continue) = true; \
  938. BOOST_FOREACH_ID(_foreach_continue) && !BOOST_FOREACH_DONE(COL); \
  939. BOOST_FOREACH_ID(_foreach_continue) ? BOOST_FOREACH_NEXT(COL) : (void)0) \
  940. if (boost::foreach_detail_::set_false(BOOST_FOREACH_ID(_foreach_continue))) {} else \
  941. for (VAR = BOOST_FOREACH_DEREF(COL); !BOOST_FOREACH_ID(_foreach_continue); BOOST_FOREACH_ID(_foreach_continue) = true)
  942. ///////////////////////////////////////////////////////////////////////////////
  943. // BOOST_REVERSE_FOREACH
  944. //
  945. // For iterating over collections in reverse order. In
  946. // all other respects, BOOST_REVERSE_FOREACH is like
  947. // BOOST_FOREACH.
  948. //
  949. #define BOOST_REVERSE_FOREACH(VAR, COL) \
  950. BOOST_FOREACH_PREAMBLE() \
  951. if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_col) = BOOST_FOREACH_CONTAIN(COL)) {} else \
  952. if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_cur) = BOOST_FOREACH_RBEGIN(COL)) {} else \
  953. if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_end) = BOOST_FOREACH_REND(COL)) {} else \
  954. for (bool BOOST_FOREACH_ID(_foreach_continue) = true; \
  955. BOOST_FOREACH_ID(_foreach_continue) && !BOOST_FOREACH_RDONE(COL); \
  956. BOOST_FOREACH_ID(_foreach_continue) ? BOOST_FOREACH_RNEXT(COL) : (void)0) \
  957. if (boost::foreach_detail_::set_false(BOOST_FOREACH_ID(_foreach_continue))) {} else \
  958. for (VAR = BOOST_FOREACH_RDEREF(COL); !BOOST_FOREACH_ID(_foreach_continue); BOOST_FOREACH_ID(_foreach_continue) = true)
  959. #endif