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