All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
fusion_algorithms.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2013 Piotr Wygocki
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
15 #ifndef PAAL_FUSION_ALGORITHMS_HPP
16 #define PAAL_FUSION_ALGORITHMS_HPP
17 
19 
20 #include <boost/fusion/include/begin.hpp>
21 
22 #include <functional>
23 
24 namespace paal {
25 namespace data_structures {
26 
32  struct Fold {
33  template <typename Functor, typename IterEnd,
34  typename AccumulatorFunctor, typename AccumulatorData>
35  typename std::result_of<AccumulatorFunctor(AccumulatorData)>::type
36  operator()(Functor, AccumulatorFunctor accumulatorFunctor,
37  AccumulatorData accumulatorData, IterEnd, IterEnd) const {
38  return accumulatorFunctor(accumulatorData);
39  }
40 
41  template <typename Functor, typename IterBegin, typename IterEnd,
42  typename AccumulatorFunctor, typename AccumulatorData,
47  typename Dummy = typename std::enable_if<
48  !std::is_same<IterEnd, IterBegin>::value>::type>
49  auto operator()(Functor f, AccumulatorFunctor accumulatorFunctor,
50  AccumulatorData accumulatorData, IterBegin begin,
51  IterEnd end) const
52  -> typename std::result_of<Functor(
53  typename boost::fusion::result_of::deref<IterBegin>::type,
54  AccumulatorFunctor, AccumulatorData,
55  // TODO Why this move is needed??? (without it doesn't compile
56  // on clang-3.4)
57  decltype(std::move(std::bind(
58  *this, f, std::placeholders::_1, std::placeholders::_2,
59  boost::fusion::next(begin), end))))>::type {
60  auto continuation = std::bind(*this, f, std::placeholders::_1,
61  std::placeholders::_2,
62  boost::fusion::next(begin), end);
63 
64  return f(*begin, accumulatorFunctor, accumulatorData, continuation);
65  }
66  };
67 
68  public:
83  template <typename Functor, typename AccumulatorFunctor, typename AccumulatorData, typename Sequence>
84  auto operator()(Functor f, AccumulatorFunctor accumulatorFunctor,
85  AccumulatorData accumulatorData, Sequence &seq) const{
86  return Fold {}
87  (f, accumulatorFunctor, accumulatorData, boost::fusion::begin(seq),
88  boost::fusion::end(seq));
89  }
90 };
91 
95 class Satisfy {
103  template <typename Predicate, typename IterEnd>
104  bool satisfy(Predicate, IterEnd, IterEnd) const {
105  return false;
106  }
107 
120  template <typename Predicate, typename IterBegin, typename IterEnd>
121  bool satisfy(Predicate pred, IterBegin begin, IterEnd end) const {
122  if (pred(*begin)) {
123  return true;
124  }
125  return satisfy(pred, boost::fusion::next(begin), end);
126  }
127 
128  public:
139  template <typename Predicate, typename Seq>
140  bool operator()(Predicate pred, Seq &seq) const {
141  return satisfy(pred, boost::fusion::begin(seq),
142  boost::fusion::end(seq));
143  }
144 };
145 
146 }
147 }
148 
149 #endif // PAAL_FUSION_ALGORITHMS_HPP
Find for StaticLazyJoin.
bool operator()(Predicate pred, Seq &seq) const
operator()
class for polymorphic join on boost fusion sequence
auto operator()(Functor f, AccumulatorFunctor accumulatorFunctor, AccumulatorData accumulatorData, Sequence &seq) const
operator()