|
Shinya Kitaoka |
810553 |
#pragma once
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TCG_FUNCTIONAL_H
|
|
Toshihiro Shimizu |
890ddd |
#define TCG_FUNCTIONAL_H
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "traits.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// std includes
|
|
Toshihiro Shimizu |
890ddd |
#include <functional></functional>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//**********************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// Logical functor combinators
|
|
Toshihiro Shimizu |
890ddd |
//**********************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
namespace tcg {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename fn1,="" fn2="" typename=""></typename>
|
|
Shinya Kitaoka |
120a6e |
class unary_and
|
|
Shinya Kitaoka |
120a6e |
: public std::unary_function<typename function_traits<fn1="">::arg_type,</typename>
|
|
Shinya Kitaoka |
120a6e |
bool> {
|
|
Shinya Kitaoka |
120a6e |
Fn1 m_fn1;
|
|
Shinya Kitaoka |
120a6e |
Fn2 m_fn2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
unary_and(const Fn1 &fn1, const Fn2 &fn2) : m_fn1(fn1), m_fn2(fn2) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool operator()(const typename function_traits<fn1>::arg_type &t) const {</fn1>
|
|
Shinya Kitaoka |
120a6e |
return m_fn1(t) && m_fn2(t);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename fn1,="" fn2="" typename=""></typename>
|
|
Shinya Kitaoka |
120a6e |
unary_and<fn1, fn2=""> and1(const Fn1 &fn1, const Fn2 &fn2) {</fn1,>
|
|
Shinya Kitaoka |
120a6e |
return unary_and<fn1, fn2="">(fn1, fn2);</fn1,>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename fn1,="" fn2="" typename=""></typename>
|
|
Shinya Kitaoka |
120a6e |
class unary_or
|
|
Shinya Kitaoka |
120a6e |
: public std::unary_function<typename function_traits<fn1="">::arg_type,</typename>
|
|
Shinya Kitaoka |
120a6e |
bool> {
|
|
Shinya Kitaoka |
120a6e |
Fn1 m_fn1;
|
|
Shinya Kitaoka |
120a6e |
Fn2 m_fn2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
unary_or(const Fn1 &fn1, const Fn2 &fn2) : m_fn1(fn1), m_fn2(fn2) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool operator()(const typename function_traits<fn1>::arg_type &t) const {</fn1>
|
|
Shinya Kitaoka |
120a6e |
return m_fn1(t) || m_fn2(t);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename fn1,="" fn2="" typename=""></typename>
|
|
Shinya Kitaoka |
120a6e |
unary_or<fn1, fn2=""> or1(const Fn1 &fn1, const Fn2 &fn2) {</fn1,>
|
|
Shinya Kitaoka |
120a6e |
return unary_or<fn1, fn2="">(fn1, fn2);</fn1,>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
} // namespace tcg
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
#endif // TCG_FUNCTIONAL_H
|