mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-16 15:14:13 +00:00
rewrite hash implementation
This commit is contained in:
parent
87ee4f4032
commit
d00e971abe
13 changed files with 262 additions and 269 deletions
|
@ -1,59 +1,74 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_BIND2ND_HPP
|
||||
#define SPROUT_FUNCTIONAL_BIND2ND_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/base.hpp>
|
||||
#include <sprout/functional/type_traits/is_strict_function.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
|
||||
// D.9.3 Class template binder2nd
|
||||
template<typename Fn, typename T = void, typename = void>
|
||||
class binder2nd;
|
||||
template<typename Fn, typename T>
|
||||
class binder2nd<
|
||||
Fn, T,
|
||||
typename std::enable_if<sprout::is_strict_binary_function<Fn>::value>::type
|
||||
>
|
||||
: public sprout::unary_function<typename Fn::first_argument_type, typename Fn::result_type>
|
||||
namespace detail {
|
||||
template<typename Fn, typename T = void, typename = void>
|
||||
class binder2nd;
|
||||
template<typename Fn, typename T>
|
||||
class binder2nd<
|
||||
Fn, T,
|
||||
typename std::enable_if<sprout::is_strict_binary_function<Fn>::value>::type
|
||||
>
|
||||
: public sprout::unary_function<typename Fn::first_argument_type, typename Fn::result_type>
|
||||
{
|
||||
public:
|
||||
typedef typename std::conditional<
|
||||
std::is_void<T>::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<typename Fn, typename T>
|
||||
class binder2nd<
|
||||
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 binder2nd(Fn const& x, value_type const& y)
|
||||
: op(x), value(y)
|
||||
{}
|
||||
template<typename U>
|
||||
SPROUT_CONSTEXPR decltype(op(std::declval<U const&>(), value))
|
||||
operator()(U const& x) const {
|
||||
return op(x, value);
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
template<typename Fn, typename T = void>
|
||||
class binder2nd
|
||||
: public sprout::detail::binder2nd<Fn, T>
|
||||
{
|
||||
public:
|
||||
typedef typename std::conditional<
|
||||
std::is_void<T>::value,
|
||||
typename Fn::second_argument_type,
|
||||
T
|
||||
>::type value_type;
|
||||
protected:
|
||||
Fn op;
|
||||
value_type value;
|
||||
typedef typename sprout::detail::binder2nd<Fn, T>::value_type value_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR binder2nd(Fn const& x, value_type const& y)
|
||||
: op(x), value(y)
|
||||
: sprout::detail::binder2nd<Fn, T>(x, y)
|
||||
{}
|
||||
SPROUT_CONSTEXPR typename Fn::result_type
|
||||
operator()(typename Fn::first_argument_type const& x) const {
|
||||
return op(x, value);
|
||||
}
|
||||
};
|
||||
template<typename Fn, typename T>
|
||||
class binder2nd<
|
||||
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 binder2nd(Fn const& x, value_type const& y)
|
||||
: op(x), value(y)
|
||||
{}
|
||||
template<typename U>
|
||||
SPROUT_CONSTEXPR decltype(op(std::declval<U const&>(), value))
|
||||
operator()(U const& x) const {
|
||||
return op(x, value);
|
||||
}
|
||||
};
|
||||
|
||||
// D.9.3 bind2nd
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue