#ifndef TESTSPR_FUNCTIONAL_HPP #define TESTSPR_FUNCTIONAL_HPP #include namespace testspr { // // do_nothing // template inline SPROUT_CONSTEXPR bool do_nothing(T const&) SPROUT_NOEXCEPT { return true; } // // is_even // template struct is_even { public: typedef T argument_type; typedef bool result_type; public: SPROUT_CONSTEXPR bool operator()(T const& t) const { return t % 2 == 0; } }; // // is_odd // template struct is_odd { public: typedef T argument_type; typedef bool result_type; public: SPROUT_CONSTEXPR bool operator()(T const& t) const { return t % 2 != 0; } }; // // is_multiple_of // template struct is_multiple_of { public: typedef T first_argument_type; typedef U second_argument_type; typedef bool result_type; public: SPROUT_CONSTEXPR bool operator()(T const& t, U const& u) const { return t % u == 0; } }; // // less // template struct less { public: typedef T first_argument_type; typedef T second_argument_type; typedef bool result_type; public: SPROUT_CONSTEXPR bool operator()(T const& lhs, T const& rhs) const { return lhs < rhs; } }; // // greater // template struct greater { public: typedef T first_argument_type; typedef T second_argument_type; typedef bool result_type; public: SPROUT_CONSTEXPR bool operator()(T const& lhs, T const& rhs) const { return lhs > rhs; } }; // // equal_to // template struct equal_to { public: typedef T first_argument_type; typedef T second_argument_type; typedef bool result_type; public: SPROUT_CONSTEXPR bool operator()(T const& lhs, T const& rhs) const { return lhs == rhs; } }; // // mod_less // template struct mod_less { public: typedef T first_argument_type; typedef T second_argument_type; typedef bool result_type; public: SPROUT_CONSTEXPR bool operator()(T const& lhs, T const& rhs) const { return lhs % mod < rhs % mod; } }; // // less_than // template struct less_than { public: typedef T argument_type; typedef bool result_type; public: T value; public: explicit SPROUT_CONSTEXPR less_than(T const& value) : value(value) {} SPROUT_CONSTEXPR bool operator()(T const& x) const { return x < value; } }; // // greater_than // template struct greater_than { public: typedef T argument_type; typedef bool result_type; public: T value; public: explicit SPROUT_CONSTEXPR greater_than(T const& value) : value(value) {} SPROUT_CONSTEXPR bool operator()(T const& x) const { return x > value; } }; // // x2 // template struct x2 { public: typedef T argument_type; typedef T result_type; public: SPROUT_CONSTEXPR T operator()(T const& t) const { return t + t; } }; // // plus // template struct plus { public: typedef T first_argument_type; typedef T second_argument_type; typedef T result_type; public: SPROUT_CONSTEXPR T operator()(T const& lhs, T const& rhs) const { return lhs + rhs; } }; // // gen_iota // template struct gen_iota { public: struct result { public: T val; gen_iota gen; public: SPROUT_CONSTEXPR T const& generated_value() const { return val; } SPROUT_CONSTEXPR gen_iota const& next_generator() const { return gen; } }; private: T val; public: explicit SPROUT_CONSTEXPR gen_iota(T const& val = T()) : val(val) {} SPROUT_CONSTEXPR result operator()() const { return result{val, gen_iota(val + 1)}; } }; // // unf_iota // template struct unf_iota { public: struct result { public: T val; public: SPROUT_CONSTEXPR T const& generated_value() const { return val; } SPROUT_CONSTEXPR T next_generator() const { return val + 1; } }; public: SPROUT_CONSTEXPR result operator()(T const& val) const { return result{val}; } }; // // x2_visitor // template class x2_visitor { public: typedef R result_type; public: template SPROUT_CONSTEXPR result_type operator()(T const& t) const { return static_cast(t + t); } }; // // x2_assign_visitor // template class x2_assign_visitor { public: typedef R result_type; public: template SPROUT_CONSTEXPR result_type operator()(T& t) const { return static_cast(t += t); } }; } // namespace testspr #endif // #ifndef TESTSPR_FUNCTIONAL_HPP