2016-05-17 03:04:11 +12:00
|
|
|
#pragma once
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
#ifndef TCG_FUNCTIONAL_H
|
|
|
|
#define TCG_FUNCTIONAL_H
|
|
|
|
|
|
|
|
#include "traits.h"
|
|
|
|
|
|
|
|
// std includes
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
//**********************************************************************************
|
|
|
|
// Logical functor combinators
|
|
|
|
//**********************************************************************************
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
namespace tcg {
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
template <typename Fn1, typename Fn2>
|
2016-06-15 18:43:10 +12:00
|
|
|
class unary_and
|
|
|
|
: public std::unary_function<typename function_traits<Fn1>::arg_type,
|
|
|
|
bool> {
|
|
|
|
Fn1 m_fn1;
|
|
|
|
Fn2 m_fn2;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
unary_and(const Fn1 &fn1, const Fn2 &fn2) : m_fn1(fn1), m_fn2(fn2) {}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
bool operator()(const typename function_traits<Fn1>::arg_type &t) const {
|
|
|
|
return m_fn1(t) && m_fn2(t);
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Fn1, typename Fn2>
|
2016-06-15 18:43:10 +12:00
|
|
|
unary_and<Fn1, Fn2> and1(const Fn1 &fn1, const Fn2 &fn2) {
|
|
|
|
return unary_and<Fn1, Fn2>(fn1, fn2);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
template <typename Fn1, typename Fn2>
|
2016-06-15 18:43:10 +12:00
|
|
|
class unary_or
|
|
|
|
: public std::unary_function<typename function_traits<Fn1>::arg_type,
|
|
|
|
bool> {
|
|
|
|
Fn1 m_fn1;
|
|
|
|
Fn2 m_fn2;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
unary_or(const Fn1 &fn1, const Fn2 &fn2) : m_fn1(fn1), m_fn2(fn2) {}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
bool operator()(const typename function_traits<Fn1>::arg_type &t) const {
|
|
|
|
return m_fn1(t) || m_fn2(t);
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Fn1, typename Fn2>
|
2016-06-15 18:43:10 +12:00
|
|
|
unary_or<Fn1, Fn2> or1(const Fn1 &fn1, const Fn2 &fn2) {
|
|
|
|
return unary_or<Fn1, Fn2>(fn1, fn2);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
} // namespace tcg
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
#endif // TCG_FUNCTIONAL_H
|