2 #ifndef BOOST_MPL_FOR_EACH_HPP_INCLUDED
3 #define BOOST_MPL_FOR_EACH_HPP_INCLUDED
5 // Copyright Aleksey Gurtovoy 2000-2004
7 // Distributed under the Boost Software License, Version 1.0.
8 // (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
11 // See http://www.boost.org/libs/mpl for documentation.
13 // $Source: /cvsroot/boost/boost/boost/mpl/for_each.hpp,v $
14 // $Date: 2004/09/04 01:33:46 $
17 #include <boost/mpl/begin_end.hpp>
18 #include <boost/mpl/apply.hpp>
19 #include <boost/mpl/bool.hpp>
20 #include <boost/mpl/next_prior.hpp>
21 #include <boost/mpl/deref.hpp>
22 #include <boost/mpl/identity.hpp>
23 #include <boost/mpl/aux_/unwrap.hpp>
25 #include <boost/type_traits/is_same.hpp>
26 #include <boost/utility/value_init.hpp>
28 namespace boost { namespace mpl {
32 template< bool done = true >
37 , typename LastIterator
38 , typename TransformFunc
52 struct for_each_impl<false>
56 , typename LastIterator
57 , typename TransformFunc
67 typedef typename deref<Iterator>::type item;
68 typedef typename apply1<TransformFunc,item>::type arg;
70 // dwa 2002/9/10 -- make sure not to invoke undefined behavior
72 value_initialized<arg> x;
73 aux::unwrap(f, 0)(boost::get(x));
75 typedef typename mpl::next<Iterator>::type iter;
76 for_each_impl<boost::is_same<iter,LastIterator>::value>
77 ::execute((iter*)0, (LastIterator*)0, (TransformFunc*)0, f);
83 // agurt, 17/mar/02: pointer default parameters are necessary to workaround
84 // MSVC 6.5 function template signature's mangling bug
87 , typename TransformOp
91 void for_each(F f, Sequence* = 0, TransformOp* = 0)
93 typedef typename begin<Sequence>::type first;
94 typedef typename end<Sequence>::type last;
96 aux::for_each_impl< boost::is_same<first,last>::value >
97 ::execute((first*)0, (last*)0, (TransformOp*)0, f);
105 void for_each(F f, Sequence* = 0)
107 for_each<Sequence, identity<> >(f);
112 #endif // BOOST_MPL_FOR_EACH_HPP_INCLUDED