2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2015-01-10 10:13:57 +00:00
|
|
|
Copyright (c) 2011-2015 Bolero MURAKAMI
|
2013-08-08 09:54:33 +00:00
|
|
|
https://github.com/bolero-MURAKAMI/Sprout
|
|
|
|
|
|
|
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
=============================================================================*/
|
2012-06-21 04:34:26 +00:00
|
|
|
#ifndef SPROUT_FUNCTIONAL_POLYMORPHIC_BIND1ST_HPP
|
|
|
|
#define SPROUT_FUNCTIONAL_POLYMORPHIC_BIND1ST_HPP
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
#include <type_traits>
|
|
|
|
#include <sprout/config.hpp>
|
|
|
|
#include <sprout/utility/forward.hpp>
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
//
|
|
|
|
// binder1st_
|
|
|
|
// bind1st_
|
|
|
|
//
|
|
|
|
template<typename Fn, typename T>
|
|
|
|
class binder1st_ {
|
|
|
|
protected:
|
|
|
|
Fn op;
|
|
|
|
T value;
|
|
|
|
public:
|
|
|
|
SPROUT_CONSTEXPR binder1st_(Fn&& x, T&& y)
|
2014-02-22 07:32:51 +00:00
|
|
|
: op(SPROUT_FORWARD(Fn, x)), value(SPROUT_FORWARD(T, y))
|
2012-06-21 04:34:26 +00:00
|
|
|
{}
|
|
|
|
template<typename Arg>
|
|
|
|
SPROUT_CONSTEXPR decltype(op(value, std::declval<Arg>()))
|
|
|
|
operator()(Arg&& x)
|
2014-08-14 13:55:49 +00:00
|
|
|
const SPROUT_NOEXCEPT_IF_EXPR(op(value, std::declval<Arg>()))
|
2012-06-21 04:34:26 +00:00
|
|
|
{
|
2014-02-22 07:32:51 +00:00
|
|
|
return op(value, SPROUT_FORWARD(Arg, x));
|
2012-06-21 04:34:26 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
template<typename Fn, typename T>
|
2012-07-15 07:04:05 +00:00
|
|
|
inline SPROUT_CONSTEXPR sprout::binder1st_<typename std::decay<Fn>::type, typename std::decay<T>::type>
|
2012-06-21 04:34:26 +00:00
|
|
|
bind1st_(Fn&& fn, T&& x) {
|
|
|
|
typedef sprout::binder1st_<typename std::decay<Fn>::type, typename std::decay<T>::type> type;
|
2014-02-22 07:32:51 +00:00
|
|
|
return type(SPROUT_FORWARD(Fn, fn), SPROUT_FORWARD(T, x));
|
2012-06-21 04:34:26 +00:00
|
|
|
}
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_FUNCTIONAL_POLYMORPHIC_BIND1ST_HPP
|