2012-04-01 13:15:09 +00:00
|
|
|
#ifndef SPROUT_FUNCTIONAL_BIND1ST_HPP
|
|
|
|
#define SPROUT_FUNCTIONAL_BIND1ST_HPP
|
|
|
|
|
2012-11-08 16:09:49 +00:00
|
|
|
#include <type_traits>
|
2012-11-27 01:00:03 +00:00
|
|
|
#include <utility>
|
2012-04-01 13:15:09 +00:00
|
|
|
#include <sprout/config.hpp>
|
2012-04-11 14:28:29 +00:00
|
|
|
#include <sprout/functional/base.hpp>
|
2012-11-15 02:54:57 +00:00
|
|
|
#include <sprout/functional/type_traits/is_strict_function.hpp>
|
2012-04-01 13:15:09 +00:00
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
// Copyright (C) 2011 RiSK (sscrisk)
|
|
|
|
|
|
|
|
// D.9.1 Class template binder1st
|
2012-11-15 02:54:57 +00:00
|
|
|
namespace detail {
|
|
|
|
template<typename Fn, typename T = void, typename = void>
|
|
|
|
class binder1st;
|
|
|
|
template<typename Fn, typename T>
|
|
|
|
class binder1st<
|
|
|
|
Fn, T,
|
|
|
|
typename std::enable_if<sprout::is_strict_binary_function<Fn>::value>::type
|
|
|
|
>
|
|
|
|
: public sprout::unary_function<typename Fn::second_argument_type, typename Fn::result_type>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef typename std::conditional<
|
|
|
|
std::is_void<T>::value,
|
|
|
|
typename Fn::first_argument_type,
|
|
|
|
T
|
|
|
|
>::type value_type;
|
|
|
|
protected:
|
|
|
|
Fn op;
|
|
|
|
value_type value;
|
|
|
|
public:
|
|
|
|
SPROUT_CONSTEXPR binder1st(Fn const& x, value_type const& y)
|
|
|
|
: op(x), value(y)
|
|
|
|
{}
|
|
|
|
SPROUT_CONSTEXPR typename Fn::result_type
|
|
|
|
operator()(typename Fn::second_argument_type const& x) const {
|
|
|
|
return op(value, x);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template<typename Fn, typename T>
|
|
|
|
class binder1st<
|
|
|
|
Fn, T,
|
|
|
|
typename std::enable_if<!sprout::is_strict_binary_function<Fn>::value>::type
|
|
|
|
> {
|
|
|
|
public:
|
|
|
|
typedef T value_type;
|
|
|
|
protected:
|
|
|
|
Fn op;
|
|
|
|
value_type value;
|
|
|
|
public:
|
|
|
|
SPROUT_CONSTEXPR binder1st(Fn const& x, value_type const& y)
|
|
|
|
: op(x), value(y)
|
|
|
|
{}
|
|
|
|
template<typename U>
|
2012-11-27 01:00:03 +00:00
|
|
|
SPROUT_CONSTEXPR decltype(std::declval<Fn const&>()(std::declval<value_type const&>(), std::declval<U const&>()))
|
2012-11-15 02:54:57 +00:00
|
|
|
operator()(U const& x) const {
|
|
|
|
return op(value, x);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace detail
|
|
|
|
template<typename Fn, typename T = void>
|
|
|
|
class binder1st
|
|
|
|
: public sprout::detail::binder1st<Fn, T>
|
2012-04-01 13:15:09 +00:00
|
|
|
{
|
2012-11-08 16:09:49 +00:00
|
|
|
public:
|
2012-11-15 02:54:57 +00:00
|
|
|
typedef typename sprout::detail::binder1st<Fn, T>::value_type value_type;
|
2012-04-01 13:15:09 +00:00
|
|
|
public:
|
2012-11-08 16:09:49 +00:00
|
|
|
SPROUT_CONSTEXPR binder1st(Fn const& x, value_type const& y)
|
2012-11-15 02:54:57 +00:00
|
|
|
: sprout::detail::binder1st<Fn, T>(x, y)
|
2012-04-01 13:15:09 +00:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
// D.9.2 bind1st
|
|
|
|
template<typename Fn, typename T>
|
2012-11-08 16:09:49 +00:00
|
|
|
inline SPROUT_CONSTEXPR sprout::binder1st<Fn, T>
|
2012-10-06 04:53:07 +00:00
|
|
|
bind1st(Fn const& fn, T const& x) {
|
2012-11-08 16:09:49 +00:00
|
|
|
return sprout::binder1st<Fn, T>(fn, typename sprout::binder1st<Fn, T>::value_type(x));
|
2012-04-01 13:15:09 +00:00
|
|
|
}
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_FUNCTIONAL_BIND1ST_HPP
|