vrshoot

view libs/assimp/boost/foreach.hpp @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line source
2 #ifndef BOOST_FOREACH
4 ///////////////////////////////////////////////////////////////////////////////
5 // A stripped down version of FOREACH for
6 // illustration purposes. NOT FOR GENERAL USE.
7 // For a complete implementation, see BOOST_FOREACH at
8 // http://boost-sandbox.sourceforge.net/vault/index.php?directory=eric_niebler
9 //
10 // Copyright 2004 Eric Niebler.
11 // Distributed under the Boost Software License, Version 1.0. (See
12 // accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
14 //
15 // Adapted to Assimp November 29th, 2008 (Alexander Gessler).
16 // Added code to handle both const and non-const iterators, simplified some
17 // parts.
18 ///////////////////////////////////////////////////////////////////////////////
20 namespace boost {
21 namespace foreach_detail {
23 ///////////////////////////////////////////////////////////////////////////////
24 // auto_any
26 struct auto_any_base
27 {
28 operator bool() const { return false; }
29 };
31 template<typename T>
32 struct auto_any : auto_any_base
33 {
34 auto_any(T const& t) : item(t) {}
35 mutable T item;
36 };
38 template<typename T>
39 T& auto_any_cast(auto_any_base const& any)
40 {
41 return static_cast<auto_any<T> const&>(any).item;
42 }
44 ///////////////////////////////////////////////////////////////////////////////
45 // FOREACH helper function
47 template<typename T>
48 auto_any<typename T::const_iterator> begin(T const& t)
49 {
50 return t.begin();
51 }
53 template<typename T>
54 auto_any<typename T::const_iterator> end(T const& t)
55 {
56 return t.end();
57 }
59 // iterator
60 template<typename T>
61 bool done(auto_any_base const& cur, auto_any_base const& end, T&)
62 {
63 typedef typename T::iterator iter_type;
64 return auto_any_cast<iter_type>(cur) == auto_any_cast<iter_type>(end);
65 }
67 template<typename T>
68 void next(auto_any_base const& cur, T&)
69 {
70 ++auto_any_cast<typename T::iterator>(cur);
71 }
73 template<typename T>
74 typename T::reference deref(auto_any_base const& cur, T&)
75 {
76 return *auto_any_cast<typename T::iterator>(cur);
77 }
79 template<typename T>
80 typename T::const_reference deref(auto_any_base const& cur, const T&)
81 {
82 return *auto_any_cast<typename T::iterator>(cur);
83 }
85 } // end foreach_detail
87 ///////////////////////////////////////////////////////////////////////////////
88 // FOREACH
90 #define BOOST_FOREACH(item, container) \
91 if(boost::foreach_detail::auto_any_base const& foreach_magic_b = boost::foreach_detail::begin(container)) {} else \
92 if(boost::foreach_detail::auto_any_base const& foreach_magic_e = boost::foreach_detail::end(container)) {} else \
93 for(;!boost::foreach_detail::done(foreach_magic_b,foreach_magic_e,container); boost::foreach_detail::next(foreach_magic_b,container)) \
94 if (bool ugly_and_unique_break = false) {} else \
95 for(item = boost::foreach_detail::deref(foreach_magic_b,container); !ugly_and_unique_break; ugly_and_unique_break = true)
97 } // end boost
99 #endif