vrshoot
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/assimp/boost/foreach.hpp Sat Feb 01 19:58:19 2014 +0200 1.3 @@ -0,0 +1,99 @@ 1.4 + 1.5 +#ifndef BOOST_FOREACH 1.6 + 1.7 +/////////////////////////////////////////////////////////////////////////////// 1.8 +// A stripped down version of FOREACH for 1.9 +// illustration purposes. NOT FOR GENERAL USE. 1.10 +// For a complete implementation, see BOOST_FOREACH at 1.11 +// http://boost-sandbox.sourceforge.net/vault/index.php?directory=eric_niebler 1.12 +// 1.13 +// Copyright 2004 Eric Niebler. 1.14 +// Distributed under the Boost Software License, Version 1.0. (See 1.15 +// accompanying file LICENSE_1_0.txt or copy at 1.16 +// http://www.boost.org/LICENSE_1_0.txt) 1.17 +// 1.18 +// Adapted to Assimp November 29th, 2008 (Alexander Gessler). 1.19 +// Added code to handle both const and non-const iterators, simplified some 1.20 +// parts. 1.21 +/////////////////////////////////////////////////////////////////////////////// 1.22 + 1.23 +namespace boost { 1.24 +namespace foreach_detail { 1.25 + 1.26 +/////////////////////////////////////////////////////////////////////////////// 1.27 +// auto_any 1.28 + 1.29 +struct auto_any_base 1.30 +{ 1.31 + operator bool() const { return false; } 1.32 +}; 1.33 + 1.34 +template<typename T> 1.35 +struct auto_any : auto_any_base 1.36 +{ 1.37 + auto_any(T const& t) : item(t) {} 1.38 + mutable T item; 1.39 +}; 1.40 + 1.41 +template<typename T> 1.42 +T& auto_any_cast(auto_any_base const& any) 1.43 +{ 1.44 + return static_cast<auto_any<T> const&>(any).item; 1.45 +} 1.46 + 1.47 +/////////////////////////////////////////////////////////////////////////////// 1.48 +// FOREACH helper function 1.49 + 1.50 +template<typename T> 1.51 +auto_any<typename T::const_iterator> begin(T const& t) 1.52 +{ 1.53 + return t.begin(); 1.54 +} 1.55 + 1.56 +template<typename T> 1.57 +auto_any<typename T::const_iterator> end(T const& t) 1.58 +{ 1.59 + return t.end(); 1.60 +} 1.61 + 1.62 +// iterator 1.63 +template<typename T> 1.64 +bool done(auto_any_base const& cur, auto_any_base const& end, T&) 1.65 +{ 1.66 + typedef typename T::iterator iter_type; 1.67 + return auto_any_cast<iter_type>(cur) == auto_any_cast<iter_type>(end); 1.68 +} 1.69 + 1.70 +template<typename T> 1.71 +void next(auto_any_base const& cur, T&) 1.72 +{ 1.73 + ++auto_any_cast<typename T::iterator>(cur); 1.74 +} 1.75 + 1.76 +template<typename T> 1.77 +typename T::reference deref(auto_any_base const& cur, T&) 1.78 +{ 1.79 + return *auto_any_cast<typename T::iterator>(cur); 1.80 +} 1.81 + 1.82 +template<typename T> 1.83 +typename T::const_reference deref(auto_any_base const& cur, const T&) 1.84 +{ 1.85 + return *auto_any_cast<typename T::iterator>(cur); 1.86 +} 1.87 + 1.88 +} // end foreach_detail 1.89 + 1.90 +/////////////////////////////////////////////////////////////////////////////// 1.91 +// FOREACH 1.92 + 1.93 +#define BOOST_FOREACH(item, container) \ 1.94 + if(boost::foreach_detail::auto_any_base const& foreach_magic_b = boost::foreach_detail::begin(container)) {} else \ 1.95 + if(boost::foreach_detail::auto_any_base const& foreach_magic_e = boost::foreach_detail::end(container)) {} else \ 1.96 + for(;!boost::foreach_detail::done(foreach_magic_b,foreach_magic_e,container); boost::foreach_detail::next(foreach_magic_b,container)) \ 1.97 + if (bool ugly_and_unique_break = false) {} else \ 1.98 + for(item = boost::foreach_detail::deref(foreach_magic_b,container); !ugly_and_unique_break; ugly_and_unique_break = true) 1.99 + 1.100 +} // end boost 1.101 + 1.102 +#endif