]> AND Private Git Repository - canny.git/blob - stc/exp/ml_stc_linux_make_v1.0/include/boost/mpl/for_each.hpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
da93a5d76e08e8556d6b6836c5c64047e34a146e
[canny.git] / stc / exp / ml_stc_linux_make_v1.0 / include / boost / mpl / for_each.hpp
1 \r
2 #ifndef BOOST_MPL_FOR_EACH_HPP_INCLUDED\r
3 #define BOOST_MPL_FOR_EACH_HPP_INCLUDED\r
4 \r
5 // Copyright Aleksey Gurtovoy 2000-2008\r
6 //\r
7 // Distributed under the Boost Software License, Version 1.0. \r
8 // (See accompanying file LICENSE_1_0.txt or copy at \r
9 // http://www.boost.org/LICENSE_1_0.txt)\r
10 //\r
11 // See http://www.boost.org/libs/mpl for documentation.\r
12 \r
13 // $Id: for_each.hpp 55648 2009-08-18 05:16:53Z agurtovoy $\r
14 // $Date: 2009-08-18 01:16:53 -0400 (Tue, 18 Aug 2009) $\r
15 // $Revision: 55648 $\r
16 \r
17 #include <boost/mpl/is_sequence.hpp>\r
18 #include <boost/mpl/begin_end.hpp>\r
19 #include <boost/mpl/apply.hpp>\r
20 #include <boost/mpl/bool.hpp>\r
21 #include <boost/mpl/next_prior.hpp>\r
22 #include <boost/mpl/deref.hpp>\r
23 #include <boost/mpl/identity.hpp>\r
24 #include <boost/mpl/assert.hpp>\r
25 #include <boost/mpl/aux_/unwrap.hpp>\r
26 \r
27 #include <boost/type_traits/is_same.hpp>\r
28 #include <boost/utility/value_init.hpp>\r
29 \r
30 namespace boost { namespace mpl {\r
31 \r
32 namespace aux {\r
33 \r
34 template< bool done = true >\r
35 struct for_each_impl\r
36 {\r
37     template<\r
38           typename Iterator\r
39         , typename LastIterator\r
40         , typename TransformFunc\r
41         , typename F\r
42         >\r
43     static void execute(\r
44           Iterator*\r
45         , LastIterator*\r
46         , TransformFunc*\r
47         , F\r
48         )\r
49     {\r
50     }\r
51 };\r
52 \r
53 template<>\r
54 struct for_each_impl<false>\r
55 {\r
56     template<\r
57           typename Iterator\r
58         , typename LastIterator\r
59         , typename TransformFunc\r
60         , typename F\r
61         >\r
62     static void execute(\r
63           Iterator*\r
64         , LastIterator*\r
65         , TransformFunc* \r
66         , F f\r
67         )\r
68     {\r
69         typedef typename deref<Iterator>::type item;\r
70         typedef typename apply1<TransformFunc,item>::type arg;\r
71     \r
72         // dwa 2002/9/10 -- make sure not to invoke undefined behavior\r
73         // when we pass arg.\r
74         value_initialized<arg> x;\r
75         aux::unwrap(f, 0)(boost::get(x));\r
76         \r
77         typedef typename mpl::next<Iterator>::type iter;\r
78         for_each_impl<boost::is_same<iter,LastIterator>::value>\r
79             ::execute( static_cast<iter*>(0), static_cast<LastIterator*>(0), static_cast<TransformFunc*>(0), f);\r
80     }\r
81 };\r
82 \r
83 } // namespace aux\r
84 \r
85 // agurt, 17/mar/02: pointer default parameters are necessary to workaround \r
86 // MSVC 6.5 function template signature's mangling bug\r
87 template<\r
88       typename Sequence\r
89     , typename TransformOp\r
90     , typename F\r
91     >\r
92 inline\r
93 void for_each(F f, Sequence* = 0, TransformOp* = 0)\r
94 {\r
95     BOOST_MPL_ASSERT(( is_sequence<Sequence> ));\r
96 \r
97     typedef typename begin<Sequence>::type first;\r
98     typedef typename end<Sequence>::type last;\r
99 \r
100     aux::for_each_impl< boost::is_same<first,last>::value >\r
101         ::execute(static_cast<first*>(0), static_cast<last*>(0), static_cast<TransformOp*>(0), f);\r
102 }\r
103 \r
104 template<\r
105       typename Sequence\r
106     , typename F\r
107     >\r
108 inline\r
109 void for_each(F f, Sequence* = 0)\r
110 {\r
111     for_each<Sequence, identity<> >(f);\r
112 }\r
113 \r
114 }}\r
115 \r
116 #endif // BOOST_MPL_FOR_EACH_HPP_INCLUDED\r