ASCO Aerial Autonomy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
exec_if.h
Go to the documentation of this file.
1 #pragma once
2 // Copyright Aleksey Gurtovoy 2000-2008
3 //
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //
8 // See http://www.boost.org/libs/mpl for documentation.
9 
10 // $Id: exec_if.hpp 55648 2009-08-18 05:16:53Z agurtovoy $
11 // $Date: 2009-08-17 22:16:53 -0700 (Mon, 17 Aug 2009) $
12 // $Revision: 55648 $
13 
23 #include <boost/mpl/apply.hpp>
24 #include <boost/mpl/assert.hpp>
25 #include <boost/mpl/aux_/unwrap.hpp>
26 #include <boost/mpl/begin_end.hpp>
27 #include <boost/mpl/bool.hpp>
28 #include <boost/mpl/deref.hpp>
29 #include <boost/mpl/identity.hpp>
30 #include <boost/mpl/is_sequence.hpp>
31 #include <boost/mpl/next_prior.hpp>
32 
33 #include <boost/type_traits/is_same.hpp>
34 #include <boost/utility/value_init.hpp>
35 
39 namespace boost {
43 namespace mpl {
44 
48 namespace aux {
49 
55 template <bool done = true> struct exec_if_impl {
56  template <typename Iterator, typename LastIterator, typename TransformFunc,
57  typename F>
68  static bool execute(Iterator *, LastIterator *, TransformFunc *, F) {
69  return true;
70  }
71 };
72 
76 template <> struct exec_if_impl<false> {
94  template <typename Iterator, typename LastIterator, typename TransformFunc,
95  typename F>
96  static bool execute(Iterator *, LastIterator *, TransformFunc *, F f) {
97  typedef typename deref<Iterator>::type item;
98  typedef typename apply1<TransformFunc, item>::type arg;
99 
100  // dwa 2002/9/10 -- make sure not to invoke undefined behavior
101  // when we pass arg.
102  value_initialized<arg> x;
103  // Only execute further actions if return from the current action is true
104  if (aux::unwrap(f, 0)(boost::get(x))) {
105  typedef typename mpl::next<Iterator>::type iter;
107  static_cast<iter *>(0), static_cast<LastIterator *>(0),
108  static_cast<TransformFunc *>(0), f);
109  }
110  return false;
111  }
112 };
113 
114 } // namespace aux
115 
116 // agurt, 17/mar/02: pointer default parameters are necessary to workaround
117 // MSVC 6.5 function template signature's mangling bug
134 template <typename Sequence, typename TransformOp, typename F>
135 inline bool exec_if(F f, Sequence * = 0, TransformOp * = 0) {
136  BOOST_MPL_ASSERT((is_sequence<Sequence>));
137 
138  typedef typename begin<Sequence>::type first;
139  typedef typename end<Sequence>::type last;
140 
142  static_cast<first *>(0), static_cast<last *>(0),
143  static_cast<TransformOp *>(0), f);
144 }
145 
158 template <typename Sequence, typename F>
159 inline bool exec_if(F f, Sequence * = 0) {
160  return exec_if<Sequence, identity<>>(f);
161 }
162 }
163 }
Default implementation of exec which returns true.
Definition: exec_if.h:55
bool exec_if(F f, Sequence *=0, TransformOp *=0)
Function to go through elements of boost sequence and apply the functor F on each element...
Definition: exec_if.h:135
static bool execute(Iterator *, LastIterator *, TransformFunc *, F f)
Definition: exec_if.h:96
static bool execute(Iterator *, LastIterator *, TransformFunc *, F)
Default implementation that returns true.
Definition: exec_if.h:68