ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/include/boost/foreach.hpp
Revision: 1.1
Committed: Tue Aug 28 17:14:43 2007 UTC (19 years, 2 months ago) by pippijn
Branch: MAIN
Log Message:
added new files

File Contents

# User Rev Content
1 pippijn 1.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     //
9    
10     #ifndef BOOST_FOREACH
11    
12     // MS compatible compilers support #pragma once
13     #if defined(_MSC_VER) && (_MSC_VER >= 1020)
14     # pragma once
15     #endif
16    
17     #include <cstddef>
18     #include <utility> // for std::pair
19    
20     #include <boost/config.hpp>
21     #include <boost/detail/workaround.hpp>
22    
23     #include <boost/mpl/bool.hpp>
24     #include <boost/mpl/eval_if.hpp>
25     #include <boost/range/end.hpp>
26     #include <boost/range/begin.hpp>
27     #include <boost/range/result_iterator.hpp>
28     #include <boost/type_traits/is_const.hpp>
29     #include <boost/iterator/iterator_traits.hpp>
30     #include <boost/utility/addressof.hpp>
31    
32     #ifndef BOOST_FOREACH_NO_CONST_RVALUE_DETECTION
33     # include <new>
34     # include <boost/aligned_storage.hpp>
35     # include <boost/utility/enable_if.hpp>
36     # include <boost/type_traits/is_array.hpp>
37     # include <boost/type_traits/remove_const.hpp>
38     #endif
39    
40     namespace boost
41     {
42    
43     // forward declarations for iterator_range
44     template<typename T>
45     class iterator_range;
46    
47     // forward declarations for sub_range
48     template<typename T>
49     class sub_range;
50    
51     namespace foreach
52     {
53    
54     ///////////////////////////////////////////////////////////////////////////////
55     // in_range
56     //
57     template<typename T>
58     inline std::pair<T, T> in_range(T begin, T end)
59     {
60     return std::make_pair(begin, end);
61     }
62    
63     } // namespace foreach
64    
65     namespace foreach_detail_
66     {
67    
68     ///////////////////////////////////////////////////////////////////////////////
69     // adl_begin/adl_end
70     //
71     template<typename T>
72     inline BOOST_DEDUCED_TYPENAME range_result_iterator<T>::type adl_begin(T &t)
73     {
74     using boost::begin;
75     typedef BOOST_DEDUCED_TYPENAME range_result_iterator<T>::type type;
76     return type(begin(t));
77     }
78    
79     template<typename T>
80     inline BOOST_DEDUCED_TYPENAME range_result_iterator<T>::type adl_end(T &t)
81     {
82     using boost::end;
83     typedef BOOST_DEDUCED_TYPENAME range_result_iterator<T>::type type;
84     return type(end(t));
85     }
86    
87     ///////////////////////////////////////////////////////////////////////////////
88     // auto_any_t/auto_any
89     //
90     struct auto_any_base
91     {
92     // auto_any_base must evaluate to false in boolean context so that
93     // they can be declared in if() statements.
94     operator bool() const
95     {
96     return false;
97     }
98     };
99    
100     template<typename T>
101     struct auto_any : auto_any_base
102     {
103     auto_any(T const &t)
104     : item(t)
105     {
106     }
107    
108     // temporaries of type auto_any will be bound to const auto_any_base
109     // references, but we still want to be able to mutate the stored
110     // data, so declare it as mutable.
111     mutable T item;
112     };
113    
114     typedef auto_any_base const &auto_any_t;
115    
116     template<typename T, typename C>
117     inline BOOST_DEDUCED_TYPENAME boost::mpl::if_<C, T const, T>::type &auto_any_cast(auto_any_t a)
118     {
119     return static_cast<auto_any<T> const &>(a).item;
120     }
121    
122     typedef boost::mpl::true_ const_;
123    
124     ///////////////////////////////////////////////////////////////////////////////
125     // type2type
126     //
127     template<typename T, typename C = boost::mpl::false_>
128     struct type2type
129     : boost::mpl::if_<C, T const, T>
130     {
131     };
132    
133     template<typename T, typename C = boost::mpl::false_>
134     struct foreach_iterator
135     {
136     typedef BOOST_DEDUCED_TYPENAME boost::mpl::eval_if<
137     C
138     , range_const_iterator<T>
139     , range_iterator<T>
140     >::type type;
141     };
142    
143     template<typename T, typename C = boost::mpl::false_>
144     struct foreach_reference
145     : iterator_reference<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>
146     {
147     };
148    
149     ///////////////////////////////////////////////////////////////////////////////
150     // encode_type
151     //
152     template<typename T>
153     inline type2type<T> *encode_type(T &, boost::mpl::false_ *)
154     {
155     return 0;
156     }
157    
158     template<typename T>
159     inline type2type<T, const_> *encode_type(T const &, boost::mpl::true_ *)
160     {
161     return 0;
162     }
163    
164     ///////////////////////////////////////////////////////////////////////////////
165     // encode_const
166     //
167     template<typename T>
168     inline boost::is_const<T> *encode_const(T &)
169     {
170     return 0;
171     }
172    
173     #ifndef BOOST_FOREACH_NO_LVALUE_RETURN_DETECTION
174     template<typename T>
175     inline boost::mpl::true_ *encode_const(T const &)
176     {
177     return 0;
178     }
179     #endif
180    
181     #ifndef BOOST_FOREACH_NO_CONST_RVALUE_DETECTION
182    
183     ///////////////////////////////////////////////////////////////////////////////
184     // rvalue_probe
185     //
186     struct rvalue_probe
187     {
188     template<typename T>
189     rvalue_probe(T const &t, bool &b)
190     : ptemp(const_cast<BOOST_DEDUCED_TYPENAME boost::remove_const<T>::type *>(&t))
191     , rvalue(b)
192     {
193     }
194    
195     template<typename U>
196     operator U()
197     {
198     rvalue = true;
199     return *static_cast<U *>(ptemp);
200     }
201    
202     template<typename V>
203     operator V &() const
204     {
205     return *static_cast<V *>(ptemp);
206     }
207    
208     void *ptemp;
209     bool &rvalue;
210     };
211    
212     ///////////////////////////////////////////////////////////////////////////////
213     // simple_variant
214     // holds either a T or a T*
215     template<typename T>
216     struct simple_variant
217     {
218     simple_variant(T *t)
219     : rvalue(false)
220     {
221     *static_cast<T **>(data.address()) = t;
222     }
223    
224     simple_variant(T const &t)
225     : rvalue(true)
226     {
227     ::new(data.address()) T(t);
228     }
229    
230     simple_variant(simple_variant const &that)
231     : rvalue(that.rvalue)
232     {
233     if(rvalue)
234     ::new(data.address()) T(*that.get());
235     else
236     *static_cast<T **>(data.address()) = that.get();
237     }
238    
239     ~simple_variant()
240     {
241     if(rvalue)
242     get()->~T();
243     }
244    
245     T *get() const
246     {
247     if(rvalue)
248     return static_cast<T *>(data.address());
249     else
250     return *static_cast<T **>(data.address());
251     }
252    
253     private:
254     enum { size = sizeof(T) > sizeof(T*) ? sizeof(T) : sizeof(T*) };
255     simple_variant &operator =(simple_variant const &);
256     bool const rvalue;
257     mutable aligned_storage<size> data;
258     };
259    
260     #elif !defined(BOOST_FOREACH_NO_RVALUE_DETECTION)
261    
262     ///////////////////////////////////////////////////////////////////////////////
263     // is_rvalue
264     //
265     template<typename T>
266     inline boost::mpl::false_ *is_rvalue(T &, int)
267     {
268     return 0;
269     }
270    
271     template<typename T>
272     inline boost::mpl::true_ *is_rvalue(T const &, ...)
273     {
274     return 0;
275     }
276    
277     #endif // BOOST_FOREACH_NO_CONST_RVALUE_DETECTION
278    
279     ///////////////////////////////////////////////////////////////////////////////
280     // set_false
281     //
282     inline bool set_false(bool &b)
283     {
284     return b = false;
285     }
286    
287     ///////////////////////////////////////////////////////////////////////////////
288     // to_ptr
289     //
290     template<typename T>
291     inline T *to_ptr(T const &t) { return 0; }
292    
293     ///////////////////////////////////////////////////////////////////////////////
294     // cheap_copy
295     // Overload this for user-defined collection types if they are inexpensive to copy.
296     // This tells BOOST_FOREACH it can avoid the r-value/l-value detection stuff.
297     inline boost::mpl::false_ *cheap_copy(...) { return 0; }
298    
299     template<typename T>
300     inline boost::mpl::true_ *cheap_copy(std::pair<T, T> *) { return 0; }
301    
302     template<typename T>
303     inline boost::mpl::true_ *cheap_copy(iterator_range<T> *) { return 0; }
304    
305     template<typename T>
306     inline boost::mpl::true_ *cheap_copy(sub_range<T> *) { return 0; }
307    
308     template<typename T>
309     inline boost::mpl::true_ *cheap_copy(T **) { return 0; }
310    
311     template<typename T,std::size_t N>
312     inline boost::mpl::false_ *cheap_copy(T (*)[N]) { return 0; }
313    
314     ///////////////////////////////////////////////////////////////////////////////
315     // derefof
316     //
317     template<typename T>
318     inline T &derefof(T *t)
319     {
320     // This is a work-around for a compiler bug in Borland. If T* is a pointer to array type U(*)[N],
321     // then dereferencing it results in a U* instead of U(&)[N]. The cast forces the issue.
322     return reinterpret_cast<T &>(
323     *const_cast<char *>(
324     reinterpret_cast<char const volatile *>(t)
325     )
326     );
327     }
328    
329     ///////////////////////////////////////////////////////////////////////////////
330     // contain
331     //
332     template<typename T>
333     inline auto_any<T> contain(T const &t, void *, boost::mpl::true_ *)
334     {
335     return t;
336     }
337    
338     #ifndef BOOST_FOREACH_NO_CONST_RVALUE_DETECTION
339     template<typename T>
340     inline auto_any<T *> contain(T &t, bool *, boost::mpl::false_ *)
341     {
342     return boost::addressof(t);
343     }
344    
345     template<typename T>
346     inline BOOST_DEDUCED_TYPENAME disable_if<
347     boost::is_array<T>
348     , auto_any<simple_variant<T const> >
349     >::type
350     contain(T const &t, bool *rvalue, boost::mpl::false_ *)
351     {
352     return *rvalue ? simple_variant<T const>(t) : simple_variant<T const>(&t);
353     }
354     #else
355     template<typename T>
356     inline auto_any<T *> contain(T &t, boost::mpl::false_ *, boost::mpl::false_ *) // l-value
357     {
358     return boost::addressof(t);
359     }
360    
361     template<typename T>
362     inline auto_any<T> contain(T const &t, boost::mpl::true_ *, boost::mpl::false_ *) // r-value
363     {
364     return t;
365     }
366     #endif
367    
368     /////////////////////////////////////////////////////////////////////////////
369     // begin
370     //
371     template<typename T, typename C>
372     inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>
373     begin(auto_any_t col, type2type<T, C> *, void *, boost::mpl::true_ *)
374     {
375     return foreach_detail_::adl_begin(auto_any_cast<T, C>(col));
376     }
377    
378     #ifndef BOOST_FOREACH_NO_CONST_RVALUE_DETECTION
379     template<typename T, typename C>
380     inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>
381     begin(auto_any_t col, type2type<T, C> *, bool *, boost::mpl::false_ *)
382     {
383     typedef BOOST_DEDUCED_TYPENAME type2type<T, C>::type type;
384     return foreach_detail_::adl_begin(derefof(auto_any_cast<type *, boost::mpl::false_>(col)));
385     }
386    
387     template<typename T>
388     inline BOOST_DEDUCED_TYPENAME disable_if<
389     boost::is_array<T>
390     , auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, boost::mpl::true_>::type>
391     >::type
392     begin(auto_any_t col, type2type<T, const_> *, bool *, boost::mpl::false_ *)
393     {
394     return foreach_detail_::adl_begin(*auto_any_cast<simple_variant<T const>, boost::mpl::false_>(col).get());
395     }
396     #else
397     template<typename T, typename C>
398     inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>
399     begin(auto_any_t col, type2type<T, C> *, boost::mpl::false_ *, boost::mpl::false_ *) // l-value
400     {
401     typedef BOOST_DEDUCED_TYPENAME type2type<T, C>::type type;
402     typedef BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type iterator;
403     return iterator(foreach_detail_::adl_begin(derefof(auto_any_cast<type *, boost::mpl::false_>(col))));
404     }
405    
406     template<typename T>
407     inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, boost::mpl::true_>::type>
408     begin(auto_any_t col, type2type<T, const_> *, boost::mpl::true_ *, boost::mpl::false_ *) // r-value
409     {
410     return foreach_detail_::adl_begin(auto_any_cast<T, boost::mpl::true_>(col));
411     }
412     #endif
413    
414     ///////////////////////////////////////////////////////////////////////////////
415     // end
416     //
417     template<typename T, typename C>
418     inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>
419     end(auto_any_t col, type2type<T, C> *, void *, boost::mpl::true_ *)
420     {
421     return foreach_detail_::adl_end(auto_any_cast<T, C>(col));
422     }
423    
424     #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
425     template<typename T, typename C>
426     inline auto_any<int>
427     end(auto_any_t col, type2type<T *, C> *, void *, boost::mpl::true_ *)
428     {
429     return 0; // not used
430     }
431     #endif
432    
433     #ifndef BOOST_FOREACH_NO_CONST_RVALUE_DETECTION
434     template<typename T, typename C>
435     inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>
436     end(auto_any_t col, type2type<T, C> *, bool *, boost::mpl::false_ *)
437     {
438     typedef BOOST_DEDUCED_TYPENAME type2type<T, C>::type type;
439     return foreach_detail_::adl_end(derefof(auto_any_cast<type *, boost::mpl::false_>(col)));
440     }
441    
442     template<typename T>
443     inline BOOST_DEDUCED_TYPENAME disable_if<
444     boost::is_array<T>
445     , auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, boost::mpl::true_>::type>
446     >::type
447     end(auto_any_t col, type2type<T, const_> *, bool *, boost::mpl::false_ *)
448     {
449     return foreach_detail_::adl_end(*auto_any_cast<simple_variant<T const>, boost::mpl::false_>(col).get());
450     }
451     #else
452     template<typename T, typename C>
453     inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type>
454     end(auto_any_t col, type2type<T, C> *, boost::mpl::false_ *, boost::mpl::false_ *) // l-value
455     {
456     typedef BOOST_DEDUCED_TYPENAME type2type<T, C>::type type;
457     typedef BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type iterator;
458     return iterator(foreach_detail_::adl_end(derefof(auto_any_cast<type *, boost::mpl::false_>(col))));
459     }
460    
461     template<typename T>
462     inline auto_any<BOOST_DEDUCED_TYPENAME foreach_iterator<T, boost::mpl::true_>::type>
463     end(auto_any_t col, type2type<T, const_> *, boost::mpl::true_ *, boost::mpl::false_ *) // r-value
464     {
465     return foreach_detail_::adl_end(auto_any_cast<T, boost::mpl::true_>(col));
466     }
467     #endif
468    
469     ///////////////////////////////////////////////////////////////////////////////
470     // done
471     //
472     template<typename T, typename C>
473     inline bool done(auto_any_t cur, auto_any_t end, type2type<T, C> *)
474     {
475     typedef BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type iter_t;
476     return auto_any_cast<iter_t, boost::mpl::false_>(cur) == auto_any_cast<iter_t, boost::mpl::false_>(end);
477     }
478    
479     #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
480     template<typename T, typename C>
481     inline bool done(auto_any_t cur, auto_any_t, type2type<T *, C> *)
482     {
483     return ! *auto_any_cast<T *, boost::mpl::false_>(cur);
484     }
485     #endif
486    
487     ///////////////////////////////////////////////////////////////////////////////
488     // next
489     //
490     template<typename T, typename C>
491     inline void next(auto_any_t cur, type2type<T, C> *)
492     {
493     typedef BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type iter_t;
494     ++auto_any_cast<iter_t, boost::mpl::false_>(cur);
495     }
496    
497     ///////////////////////////////////////////////////////////////////////////////
498     // deref
499     //
500     template<typename T, typename C>
501     inline BOOST_DEDUCED_TYPENAME foreach_reference<T, C>::type
502     deref(auto_any_t cur, type2type<T, C> *)
503     {
504     typedef BOOST_DEDUCED_TYPENAME foreach_iterator<T, C>::type iter_t;
505     return *auto_any_cast<iter_t, boost::mpl::false_>(cur);
506     }
507    
508     } // namespace foreach_detail_
509     } // namespace boost
510    
511     #ifndef BOOST_FOREACH_NO_CONST_RVALUE_DETECTION
512     ///////////////////////////////////////////////////////////////////////////////
513     // R-values and const R-values supported here
514     ///////////////////////////////////////////////////////////////////////////////
515    
516     // A sneaky way to get the type of the collection without evaluating the expression
517     # define BOOST_FOREACH_TYPEOF(COL) \
518     (true ? 0 : boost::foreach_detail_::encode_type(COL, boost::foreach_detail_::encode_const(COL)))
519    
520     // Evaluate the collection expression, and detect if it is an l-value or and r-value
521     # define BOOST_FOREACH_EVAL(COL) \
522     (true ? boost::foreach_detail_::rvalue_probe((COL), _foreach_rvalue) : (COL))
523    
524     // Declare a variable to track the rvalue-ness of the collection expression
525     # define BOOST_FOREACH_DEFINE_RVALUE() \
526     if (bool _foreach_rvalue = false) {} else
527    
528     // The R-value/L-value-ness of the collection expression is determined dynamically
529     # define BOOST_FOREACH_RVALUE(COL) \
530     (&_foreach_rvalue)
531    
532     # define BOOST_FOREACH_CHEAP_COPY(COL) \
533     (true ? 0 : boost::foreach_detail_::cheap_copy(boost::foreach_detail_::to_ptr(COL)))
534    
535     # define BOOST_FOREACH_NOOP(COL) \
536     ((void)0)
537    
538     #elif !defined(BOOST_FOREACH_NO_RVALUE_DETECTION)
539     ///////////////////////////////////////////////////////////////////////////////
540     // R-values supported here, const R-values NOT supported here
541     ///////////////////////////////////////////////////////////////////////////////
542    
543     // A sneaky way to get the type of the collection without evaluating the expression
544     # define BOOST_FOREACH_TYPEOF(COL) \
545     (true ? 0 : boost::foreach_detail_::encode_type(COL, boost::foreach_detail_::encode_const(COL)))
546    
547     // Evaluate the collection expression
548     # define BOOST_FOREACH_EVAL(COL) \
549     (COL)
550    
551     // No variable is needed to track the rvalue-ness of the collection expression
552     # define BOOST_FOREACH_DEFINE_RVALUE() \
553     /**/
554    
555     // Determine whether the collection expression is an l-value or an r-value.
556     // NOTE: this gets the answer for const R-values wrong.
557     # define BOOST_FOREACH_RVALUE(COL) \
558     (true ? 0 : boost::foreach_detail_::is_rvalue((COL), 0))
559    
560     # define BOOST_FOREACH_CHEAP_COPY(COL) \
561     (true ? 0 : boost::foreach_detail_::cheap_copy(boost::foreach_detail_::to_ptr(COL)))
562    
563     # define BOOST_FOREACH_NOOP(COL) \
564     ((void)0)
565    
566     #else
567     ///////////////////////////////////////////////////////////////////////////////
568     // R-values NOT supported here
569     ///////////////////////////////////////////////////////////////////////////////
570    
571     // A sneaky way to get the type of the collection without evaluating the expression
572     # define BOOST_FOREACH_TYPEOF(COL) \
573     (true ? 0 : boost::foreach_detail_::encode_type(COL, boost::foreach_detail_::encode_const(COL)))
574    
575     // Evaluate the collection expression
576     # define BOOST_FOREACH_EVAL(COL) \
577     (COL)
578    
579     // No variable is needed to track the rvalue-ness of the collection expression
580     # define BOOST_FOREACH_DEFINE_RVALUE() \
581     /**/
582    
583     // Can't use R-values with BOOST_FOREACH
584     # define BOOST_FOREACH_RVALUE(COL) \
585     (static_cast<boost::mpl::false_ *>(0))
586    
587     # define BOOST_FOREACH_CHEAP_COPY(COL) \
588     (true ? 0 : boost::foreach_detail_::cheap_copy(boost::foreach_detail_::to_ptr(COL)))
589    
590     // Attempt to make uses of BOOST_FOREACH with non-lvalues fail to compile
591     // BUGBUG but cheap-to-copy containers *would* be handled correctly. Hrm.
592     # define BOOST_FOREACH_NOOP(COL) \
593     ((void)&(COL))
594    
595     #endif
596    
597    
598     #define BOOST_FOREACH_CONTAIN(COL) \
599     boost::foreach_detail_::contain( \
600     BOOST_FOREACH_EVAL(COL) \
601     , BOOST_FOREACH_RVALUE(COL) \
602     , BOOST_FOREACH_CHEAP_COPY(COL))
603    
604     #define BOOST_FOREACH_BEGIN(COL) \
605     boost::foreach_detail_::begin( \
606     _foreach_col \
607     , BOOST_FOREACH_TYPEOF(COL) \
608     , BOOST_FOREACH_RVALUE(COL) \
609     , BOOST_FOREACH_CHEAP_COPY(COL))
610    
611     #define BOOST_FOREACH_END(COL) \
612     boost::foreach_detail_::end( \
613     _foreach_col \
614     , BOOST_FOREACH_TYPEOF(COL) \
615     , BOOST_FOREACH_RVALUE(COL) \
616     , BOOST_FOREACH_CHEAP_COPY(COL))
617    
618     #define BOOST_FOREACH_DONE(COL) \
619     boost::foreach_detail_::done( \
620     _foreach_cur \
621     , _foreach_end \
622     , BOOST_FOREACH_TYPEOF(COL))
623    
624     #define BOOST_FOREACH_NEXT(COL) \
625     boost::foreach_detail_::next( \
626     _foreach_cur \
627     , BOOST_FOREACH_TYPEOF(COL))
628    
629     #define BOOST_FOREACH_DEREF(COL) \
630     boost::foreach_detail_::deref( \
631     _foreach_cur \
632     , BOOST_FOREACH_TYPEOF(COL))
633    
634     ///////////////////////////////////////////////////////////////////////////////
635     // BOOST_FOREACH
636     //
637     // For iterating over collections. Collections can be
638     // arrays, null-terminated strings, or STL containers.
639     // The loop variable can be a value or reference. For
640     // example:
641     //
642     // std::list<int> int_list(/*stuff*/);
643     // BOOST_FOREACH(int &i, int_list)
644     // {
645     // /*
646     // * loop body goes here.
647     // * i is a reference to the int in int_list.
648     // */
649     // }
650     //
651     // Alternately, you can declare the loop variable first,
652     // so you can access it after the loop finishes. Obviously,
653     // if you do it this way, then the loop variable cannot be
654     // a reference.
655     //
656     // int i;
657     // BOOST_FOREACH(i, int_list)
658     // { ... }
659     //
660     #define BOOST_FOREACH(VAR, COL) \
661     BOOST_FOREACH_DEFINE_RVALUE() \
662     if (boost::foreach_detail_::auto_any_t _foreach_col = BOOST_FOREACH_CONTAIN(COL)) {} else \
663     if (boost::foreach_detail_::auto_any_t _foreach_cur = BOOST_FOREACH_BEGIN(COL)) {} else \
664     if (boost::foreach_detail_::auto_any_t _foreach_end = BOOST_FOREACH_END(COL)) {} else \
665     for (bool _foreach_continue = true; \
666     _foreach_continue && !BOOST_FOREACH_DONE(COL); \
667     _foreach_continue ? BOOST_FOREACH_NEXT(COL) : BOOST_FOREACH_NOOP(COL)) \
668     if (boost::foreach_detail_::set_false(_foreach_continue)) {} else \
669     for (VAR = BOOST_FOREACH_DEREF(COL); !_foreach_continue; _foreach_continue = true)
670    
671     #define foreach BOOST_FOREACH
672    
673     #endif