Toshihiro Shimizu 890ddd
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
Toshihiro Shimizu 890ddd
namespace tcg
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename fn1,="" fn2="" typename=""></typename>
Toshihiro Shimizu 890ddd
class unary_and : public std::unary_function<typename function_traits<fn1="">::arg_type, bool></typename>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	Fn1 m_fn1;
Toshihiro Shimizu 890ddd
	Fn2 m_fn2;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	unary_and(const Fn1 &fn1, const Fn2 &fn2)
Toshihiro Shimizu 890ddd
		: m_fn1(fn1), m_fn2(fn2) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool operator()(const typename function_traits<fn1>::arg_type &t) const</fn1>
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return m_fn1(t) && m_fn2(t);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename fn1,="" fn2="" typename=""></typename>
Toshihiro Shimizu 890ddd
unary_and<fn1, fn2=""> and1(const Fn1 &fn1, const Fn2 &fn2)</fn1,>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	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>
Toshihiro Shimizu 890ddd
class unary_or : public std::unary_function<typename function_traits<fn1="">::arg_type, bool></typename>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	Fn1 m_fn1;
Toshihiro Shimizu 890ddd
	Fn2 m_fn2;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	unary_or(const Fn1 &fn1, const Fn2 &fn2)
Toshihiro Shimizu 890ddd
		: m_fn1(fn1), m_fn2(fn2) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool operator()(const typename function_traits<fn1>::arg_type &t) const</fn1>
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return m_fn1(t) || m_fn2(t);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename fn1,="" fn2="" typename=""></typename>
Toshihiro Shimizu 890ddd
unary_or<fn1, fn2=""> or1(const Fn1 &fn1, const Fn2 &fn2)</fn1,>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return unary_or<fn1, fn2="">(fn1, fn2);</fn1,>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} // namespace tcg
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif // TCG_FUNCTIONAL_H