#ifndef SPROUT_FUNCTIONAL_BIND2ND_HPP #define SPROUT_FUNCTIONAL_BIND2ND_HPP #include #include #include #include #include namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) // D.9.3 Class template binder2nd namespace detail { template class binder2nd; template class binder2nd< Fn, T, typename std::enable_if::value>::type > : public sprout::unary_function { public: typedef typename std::conditional< std::is_void::value, typename Fn::second_argument_type, T >::type value_type; protected: Fn op; value_type value; public: SPROUT_CONSTEXPR binder2nd(Fn const& x, value_type const& y) : op(x), value(y) {} SPROUT_CONSTEXPR typename Fn::result_type operator()(typename Fn::first_argument_type const& x) const { return op(x, value); } }; template class binder2nd< Fn, T, typename std::enable_if::value>::type > { public: typedef T value_type; protected: Fn op; value_type value; public: SPROUT_CONSTEXPR binder2nd(Fn const& x, value_type const& y) : op(x), value(y) {} template SPROUT_CONSTEXPR decltype(std::declval()(std::declval(), std::declval())) operator()(U const& x) const { return op(x, value); } }; } // namespace detail template class binder2nd : public sprout::detail::binder2nd { public: typedef typename sprout::detail::binder2nd::value_type value_type; public: SPROUT_CONSTEXPR binder2nd(Fn const& x, value_type const& y) : sprout::detail::binder2nd(x, y) {} }; // D.9.3 bind2nd template inline SPROUT_CONSTEXPR sprout::binder2nd bind2nd(Fn const& fn, T const& x) { return sprout::binder2nd(fn, typename sprout::binder2nd::value_type(x)); } } // namespace sprout #endif // #ifndef SPROUT_FUNCTIONAL_BIND2ND_HPP