16 #ifndef PAAL_FUNCTORS_HPP
17 #define PAAL_FUNCTORS_HPP
19 #define BOOST_RESULT_OF_USE_DECLTYPE
23 #include <boost/range/adaptor/transformed.hpp>
24 #include <boost/range/iterator_range.hpp>
45 template <
class... Args>
59 template <
typename... Args>
void operator()(Args &&... args)
const {}
78 template <
typename... Args> T
operator()(Args &&... args)
const {
104 template <
typename... Args> T
operator()(Args &&... args)
const {
120 template <
typename T>
137 template <
typename Arg>
auto operator()(Arg &&arg) const->Arg {
138 return std::forward<Arg>(arg);
152 template <
typename F,
typename G>
154 return std::bind(f, std::bind(g, std::placeholders::_1));
167 template <
typename F,
typename... Fs>
174 template <
typename T>
void get(T t) {}
202 template <
class Tuple>
205 return m_f(get<0>(t), get<1>(t));
249 template <
typename... Args>
void operator()(Args &&... args)
const {
266 template <
typename T> T
operator()(
const T &t)
const {
return t; }
275 template <
typename Functor,
typename CounterType =
int>
285 : m_cnt(&cnt), m_functor(std::move(f)) {}
294 template <
typename... Args>
296 ->decltype(std::declval<Functor>()(std::forward<Args>(args)...)) {
298 return m_functor(std::forward<Args>(args)...);
316 template <
typename CounterType =
int,
typename Functor>
335 : m_array(array), m_offset(offset) {}
338 typedef decltype(std::declval<const Array>()[0]) Value;
347 Value operator()(
int a)
const {
return m_array.get()[a + m_offset]; }
350 std::reference_wrapper<const Array> m_array;
363 template <
typename Array>
402 template <
typename... Args>
404 std::declval<Functor>()(std::forward<Args>(args)...)) {
405 return m_f.get()(std::forward<Args>(args)...);
409 std::reference_wrapper<const Functor> m_f;
420 template <
typename Functor>
448 template <
typename Iterator>
450 std::declval<Functor>()(*iter)) {
466 template <
typename Functor>
489 auto operator()(
const T &x,
const T &y)
const->decltype(x > y) {
508 auto operator()(
const T &x,
const T &y)
const->decltype(x < y) {
527 template <
class T1,
class T2>
528 auto operator()(
const T1 &x,
const T2 &y)
const->decltype(x >= y) {
547 template <
class T1,
class T2>
548 auto operator()(
const T1 &x,
const T2 &y)
const->decltype(x <= y) {
567 auto operator()(
const T &x,
const T &y)
const->decltype(x == y) {
584 template <
class T,
class U>
604 auto operator()(
const T &x,
const T &y)
const->decltype(x != y) {
612 template <
typename Functor,
typename Compare = less>
631 template <
typename T>
632 auto operator()(
const T &left,
const T &right)
const->decltype(
633 std::declval<Compare>()(std::declval<Functor>()(left),
634 std::declval<Functor>()(right))) {
635 return m_c(m_f(left), m_f(right));
653 template <
typename Functor,
typename Compare = less>
660 template <
typename Functor,
typename ScaleType,
661 typename ReturnType = ScaleType>
680 template <
typename Arg> ReturnType
operator()(Arg &&arg)
const {
681 return m_s * m_f(std::forward<Arg>(arg));
700 template <
typename ScaleType,
typename ReturnType = ScaleType,
720 template <
typename T1,
typename T2>
722 -> decltype(std::forward<T1>(left) + std::forward<T2>(right)) {
723 return std::forward<T1>(left) + std::forward<T2>(right);
738 template <
typename T>
740 const T &right)
const->decltype(left - right) {
754 template <
typename T>
756 const T &right)
const->decltype(std::max(left, right)) {
757 return std::max(left, right);
770 template <
typename T>
772 const T &right)
const->decltype(std::min(left, right)) {
773 return std::min(left, right);
792 template <
typename T>
auto operator()(
const T &b)
const->decltype(!b) {
808 template <
typename T>
810 const T &right)
const->decltype(left || right) {
811 return left || right;
826 template <
typename T>
828 const T &right)
const->decltype(left &&right) {
829 return left && right;
835 template <
typename FunctorLeft,
typename FunctorRight,
typename Operator>
845 FunctorRight right = FunctorRight(),
846 Operator op = Operator())
847 : m_left(std::move(left)), m_right(std::move(right)),
848 m_operator(std::move(op)) {}
857 template <
typename... Args>
858 auto operator()(Args &&... args) const->decltype(std::declval<Operator>()(
859 std::declval<FunctorLeft>()(std::forward<Args>(args)...),
860 std::declval<FunctorRight>()(std::forward<Args>(args)...))) {
861 return m_operator(m_left(std::forward<Args>(args)...),
862 m_right(std::forward<Args>(args)...));
867 FunctorRight m_right;
883 template <
typename FunctorLeft,
typename FunctorRight,
typename Operator>
887 std::move(left), std::move(right), std::move(op));
910 template <
typename... Args>
912 std::declval<Functor>()(std::forward<Args>(args)...)) {
913 return !m_functor(std::forward<Args>(args)...);
921 template <
typename Functor>
927 template <
typename FunctorLeft,
typename FunctorRight>
939 FunctorRight right = FunctorRight())
940 :
base(std::move(left), std::move(right)) {}
944 template <
typename FunctorLeft,
typename FunctorRight>
946 FunctorRight right) {
952 template <
typename FunctorLeft,
typename FunctorRight>
964 FunctorRight right = FunctorRight())
965 :
base(std::move(left), std::move(right)) {}
969 template <
typename FunctorLeft,
typename FunctorRight>
976 template <
typename FunctorLeft,
typename FunctorRight>
978 FunctorLeft, FunctorRight, not_equal_to> {
989 FunctorRight right = FunctorRight())
990 :
base(std::move(left), std::move(right)) {}
994 template <
typename FunctorLeft,
typename FunctorRight>
1001 template <std::
size_t I>
1009 template <
typename Tuple>
1012 decltype(std::get<I>(std::forward<Tuple>(tuple))) {
1013 return std::get<I>(std::forward<Tuple>(tuple));
1019 #endif // PAAL_FUNCTORS_HPP
lift_iterator_functor(Functor f)
constructor
auto make_or_functor(FunctorLeft left, FunctorRight right)
make for or_functor
Functor returns always the same number (dynamic version).
auto operator()(const T &b) const -> decltype(!b)
operator()
auto operator()(const T &x, const T &y) const -> decltype(x > y)
operator()
auto operator()(Args &&...args) -> decltype(std::declval< Functor >()(std::forward< Args >(args)...))
increments the counter and checks if the given limit is reached.
dynamic_return_constant_functor(T t)
constructor
tuple_uncurry(F f)
constructor
void operator()(Args &&...args) const
operator
Type that can be constructed from anything and has no other functionality.
counting_functor_adaptor(Functor f, CounterType &cnt)
Constructor.
auto make_tuple_uncurry(F f)
make for tuple_uncurry
auto operator()(const T &left, const T &right) const -> decltype(std::min(left, right))
operator()
and_functor(FunctorLeft left=FunctorLeft(), FunctorRight right=FunctorRight())
constructor
auto make_dynamic_return_constant_functor(T t)
make function for dynamic_return_constant_functor
auto operator()(const T1 &x, const T2 &y) const -> decltype(x<=y)
operator()
Functor returns always the same number. The number has to be known at compile time.
auto operator()(const T1 &x, const T2 &y) const -> decltype(x >=y)
operator()
Adapts array as function, providing operator()().
lift_binary_operator_functor(FunctorLeft left=FunctorLeft(), FunctorRight right=FunctorRight(), Operator op=Operator())
constructor
auto make_xor_functor(FunctorLeft left, FunctorRight right)
make for Xor
For given functor f, lift_iterator_functor provides operator()(Iterator iterator) which returns f(*it...
array_to_functor(const Array &array, int offset=0)
constructor
T operator()(Args &&...args) const
operator
auto make_functor_to_comparator(Functor functor, Compare compare=Compare())
make for functor to comparator
void operator()(Args &&...args) const
operator()
auto compose(F f, G g)
functor composition: x -> f(g(x))
auto operator()(const T &x, const T &y) const -> decltype(x!=y)
operator
auto operator()(Iterator iter) const -> decltype(std::declval< Functor >()(*iter))
operator()
auto operator()(const T &left, const T &right) const -> decltype(std::declval< Compare >()(std::declval< Functor >()(left), std::declval< Functor >()(right)))
operator()
auto make_assignable_functor(Functor &f)
make function for assignable_functor
xor_functor(FunctorLeft left=FunctorLeft(), FunctorRight right=FunctorRight())
constructor
auto make_not_functor(Functor functor)
make for Not
ReturnType operator()(Arg &&arg) const
operator()
auto operator()(const T &left, const T &right) const -> decltype(left||right)
operator
auto operator()(Arg &&arg) const -> Arg
operator()
scale_functor(Functor f, ScaleType s)
constructor
auto operator()(Args &&...args) const -> decltype(std::declval< Functor >()(std::forward< Args >(args)...))
operator()
auto make_array_to_functor(const Array &a, int offset=0)
make function for array_to_functor
auto make_lift_binary_operator_functor(FunctorLeft left, FunctorRight right, Operator op)
make function for lift_binary_operator_functor
Class for comparing floating point.
auto operator()(const T &left, const T &right) const -> decltype(left &&right)
operator()
Functor that scales another functor.
auto operator()(Tuple &&t) const
operator
auto make_lift_iterator_functor(Functor f)
make function for lift_iterator_functor
functor_to_comparator(Functor f, Compare c=Compare())
constructor
auto operator()(T &&t, U &&u) const -> decltype(t==u)
operator()
auto make_counting_functor_adaptor(Functor f, CounterType &cnt)
make function for counting_functor_adaptor
functors calls assert(false).
functor for std::tuple::get<I>
functor returns its argument
transforms a functor taking multiple parameters into a functor taking a tuple parameter.
TODO equivalent to c++14 equal_to<>, remove when appears.
not_functor(Functor functor=Functor())
constructor
auto operator()(const T &x, const T &y) const -> decltype(x==y)
operator()
T operator()(const T &t) const
operator()
auto operator()(Tuple &&tuple) const -> decltype(std::get< I >(std::forward< Tuple >(tuple)))
operator()
auto operator()(T1 &&left, T2 &&right) const -> decltype(std::forward< T1 >(left)+std::forward< T2 >(right))
operator()
assignable_functor & operator=(Functor &f)
assign operator
ignore_param(Args &&...)
constructor
auto make_scale_functor(Functor f, ScaleType s)
make for scale_functor
auto operator()(Args &&...args) const -> decltype(std::declval< Functor >()(std::forward< Args >(args)...))
operator()
auto operator()(Args &&...args) const -> decltype(std::declval< Operator >()(std::declval< FunctorLeft >()(std::forward< Args >(args)...), std::declval< FunctorRight >()(std::forward< Args >(args)...)))
operator
T operator()(Args &&...args) const
operator
auto make_and_functor(FunctorLeft left, FunctorRight right)
make and_functor
auto operator()(const T &left, const T &right) const -> decltype(std::max(left, right))
operator()
or_functor(FunctorLeft left=FunctorLeft(), FunctorRight right=FunctorRight())
constructor
auto operator()(const T &left, const T &right) const -> decltype(left-right)
operator()
assignable_functor(Functor const &f)
constructor
auto operator()(const T &x, const T &y) const -> decltype(x< y)
operator()
Wrapper around a functor which adds assigmnent operator as well as default constructor. Note, this struct might be dangerous. Using this struct correctly requires the underlying functor to live at least as long as this wrapper.