mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
add functional/equiv
fix is_bind_expression add polymorphic version not1, not2
This commit is contained in:
parent
d9e9c23f67
commit
ffb3ccece8
5 changed files with 191 additions and 21 deletions
|
@ -804,6 +804,14 @@ namespace sprout {
|
|||
struct is_bind_expression<sprout::res_binder<Result, Signature> >
|
||||
: public std::true_type
|
||||
{};
|
||||
template<typename Signature>
|
||||
struct is_bind_expression<sprout::cbinder<Signature> >
|
||||
: public std::true_type
|
||||
{};
|
||||
template<typename Result, typename Signature>
|
||||
struct is_bind_expression<sprout::res_cbinder<Result, Signature> >
|
||||
: public std::true_type
|
||||
{};
|
||||
|
||||
namespace detail {
|
||||
template<std::size_t N, typename BoundArg, typename = void>
|
||||
|
|
95
sprout/functional/equiv.hpp
Normal file
95
sprout/functional/equiv.hpp
Normal file
|
@ -0,0 +1,95 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2013 Bolero MURAKAMI
|
||||
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)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_FUNCTIONAL_EQUIV_HPP
|
||||
#define SPROUT_FUNCTIONAL_EQUIV_HPP
|
||||
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/type_traits/is_strict_function.hpp>
|
||||
#include <sprout/functional/less.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
template<typename Compare, bool IsStrict = sprout::is_strict_binary_function<Compare>::value>
|
||||
class equiv_adaptor_impl;
|
||||
|
||||
template<typename Compare>
|
||||
class equiv_adaptor_impl<Compare, true> {
|
||||
public:
|
||||
typedef typename Compare::first_argument_type first_argument_type;
|
||||
typedef typename Compare::second_argument_type second_argument_type;
|
||||
typedef bool result_type;
|
||||
protected:
|
||||
Compare fn;
|
||||
public:
|
||||
explicit SPROUT_CONSTEXPR equiv_adaptor_impl(Compare const& comp)
|
||||
: fn(comp)
|
||||
{}
|
||||
SPROUT_CONSTEXPR bool operator()(typename Compare::first_argument_type const& x, typename Compare::second_argument_type const& y) const {
|
||||
return !fn(x, y) && !fn(y, x);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Compare>
|
||||
class equiv_adaptor_impl<Compare, false> {
|
||||
protected:
|
||||
Compare fn;
|
||||
public:
|
||||
explicit SPROUT_CONSTEXPR equiv_adaptor_impl(Compare const& comp)
|
||||
: fn(comp)
|
||||
{}
|
||||
template<typename T, typename U>
|
||||
SPROUT_CONSTEXPR decltype(!std::declval<Compare const&>()(std::declval<T>(), std::declval<U>()) && !std::declval<Compare const&>()(std::declval<U>(), std::declval<T>()))
|
||||
operator()(T&& x, U&& y) const {
|
||||
return !fn(sprout::forward<T>(x), sprout::forward<U>(y)) && !fn(sprout::forward<U>(y), sprout::forward<T>(x));
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// equiv_adaptor
|
||||
//
|
||||
template<typename Compare = void>
|
||||
class equiv_adaptor
|
||||
: public sprout::detail::equiv_adaptor_impl<Compare>
|
||||
{
|
||||
public:
|
||||
explicit SPROUT_CONSTEXPR equiv_adaptor(Compare const& comp)
|
||||
: sprout::detail::equiv_adaptor_impl<Compare>(comp)
|
||||
{}
|
||||
};
|
||||
template<>
|
||||
class equiv_adaptor<void>
|
||||
: public sprout::detail::equiv_adaptor_impl<sprout::less<> >
|
||||
{
|
||||
public:
|
||||
SPROUT_CONSTEXPR equiv_adaptor()
|
||||
: sprout::detail::equiv_adaptor_impl<sprout::less<> >(sprout::less<>())
|
||||
{}
|
||||
explicit SPROUT_CONSTEXPR equiv_adaptor(sprout::less<> const& comp)
|
||||
: sprout::detail::equiv_adaptor_impl<sprout::less<> >(comp)
|
||||
{}
|
||||
};
|
||||
|
||||
//
|
||||
// equiv
|
||||
//
|
||||
template<typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::equiv_adaptor<Compare>
|
||||
equiv(Compare const& comp) {
|
||||
return sprout::equiv_adaptor<Compare>(comp);
|
||||
}
|
||||
inline SPROUT_CONSTEXPR sprout::equiv_adaptor<>
|
||||
equiv() {
|
||||
return sprout::equiv_adaptor<>();
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_EQUIV_HPP
|
|
@ -15,5 +15,6 @@
|
|||
#include <sprout/functional/bitwise.hpp>
|
||||
#include <sprout/functional/binder.hpp>
|
||||
#include <sprout/functional/negator.hpp>
|
||||
#include <sprout/functional/equiv.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_FUNCTOR_HPP
|
||||
|
|
|
@ -9,24 +9,57 @@
|
|||
#define SPROUT_FUNCTIONAL_NOT1_HPP
|
||||
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/type_traits/is_strict_function.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
template<typename Predicate, bool IsStrict = sprout::is_strict_unary_function<Predicate>::value>
|
||||
class unary_negate_impl;
|
||||
|
||||
template<typename Predicate>
|
||||
class unary_negate_impl<Predicate, true> {
|
||||
public:
|
||||
typedef typename Predicate::argument_type argument_type;
|
||||
typedef bool result_type;
|
||||
protected:
|
||||
Predicate fn;
|
||||
public:
|
||||
explicit SPROUT_CONSTEXPR unary_negate_impl(Predicate const& pred)
|
||||
: fn(pred)
|
||||
{}
|
||||
SPROUT_CONSTEXPR bool operator()(typename Predicate::argument_type const& x) const {
|
||||
return !fn(x);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Predicate>
|
||||
class unary_negate_impl<Predicate, false> {
|
||||
protected:
|
||||
Predicate fn;
|
||||
public:
|
||||
explicit SPROUT_CONSTEXPR unary_negate_impl(Predicate const& pred)
|
||||
: fn(pred)
|
||||
{}
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR decltype(!std::declval<Predicate const&>()(std::declval<T>()))
|
||||
operator()(T&& x) const {
|
||||
return !fn(sprout::forward<T>(x));
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
// 20.8.8 negators
|
||||
template<typename Predicate>
|
||||
class unary_negate {
|
||||
public:
|
||||
typedef typename Predicate::argument_type argument_type;
|
||||
typedef bool result_type;
|
||||
protected:
|
||||
Predicate fn;
|
||||
class unary_negate
|
||||
: public sprout::detail::unary_negate_impl<Predicate>
|
||||
{
|
||||
public:
|
||||
explicit SPROUT_CONSTEXPR unary_negate(Predicate const& pred)
|
||||
: fn(pred)
|
||||
: sprout::detail::unary_negate_impl<Predicate>(pred)
|
||||
{}
|
||||
SPROUT_CONSTEXPR bool operator()(typename Predicate::argument_type const& x) const {
|
||||
return !fn(x);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Predicate>
|
||||
|
|
|
@ -9,25 +9,58 @@
|
|||
#define SPROUT_FUNCTIONAL_NOT2_HPP
|
||||
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/type_traits/is_strict_function.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
template<typename Predicate, bool IsStrict = sprout::is_strict_binary_function<Predicate>::value>
|
||||
class binary_negate_impl;
|
||||
|
||||
template<typename Predicate>
|
||||
class binary_negate_impl<Predicate, true> {
|
||||
public:
|
||||
typedef typename Predicate::first_argument_type first_argument_type;
|
||||
typedef typename Predicate::second_argument_type second_argument_type;
|
||||
typedef bool result_type;
|
||||
protected:
|
||||
Predicate fn;
|
||||
public:
|
||||
explicit SPROUT_CONSTEXPR binary_negate_impl(Predicate const& pred)
|
||||
: fn(pred)
|
||||
{}
|
||||
SPROUT_CONSTEXPR bool operator()(typename Predicate::first_argument_type const& x, typename Predicate::second_argument_type const& y) const {
|
||||
return !fn(x, y);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Predicate>
|
||||
class binary_negate_impl<Predicate, false> {
|
||||
protected:
|
||||
Predicate fn;
|
||||
public:
|
||||
explicit SPROUT_CONSTEXPR binary_negate_impl(Predicate const& pred)
|
||||
: fn(pred)
|
||||
{}
|
||||
template<typename T, typename U>
|
||||
SPROUT_CONSTEXPR decltype(!std::declval<Predicate const&>()(std::declval<T>(), std::declval<U>()))
|
||||
operator()(T&& x, U&& y) const {
|
||||
return !fn(sprout::forward<T>(x), sprout::forward<U>(y));
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
// 20.8.8 negators
|
||||
template<typename Predicate>
|
||||
class binary_negate {
|
||||
public:
|
||||
typedef typename Predicate::first_argument_type first_argument_type;
|
||||
typedef typename Predicate::second_argument_type second_argument_type;
|
||||
typedef bool result_type;
|
||||
protected:
|
||||
Predicate fn;
|
||||
class binary_negate
|
||||
: public sprout::detail::binary_negate_impl<Predicate>
|
||||
{
|
||||
public:
|
||||
explicit SPROUT_CONSTEXPR binary_negate(Predicate const& pred)
|
||||
: fn(pred)
|
||||
: sprout::detail::binary_negate_impl<Predicate>(pred)
|
||||
{}
|
||||
SPROUT_CONSTEXPR bool operator()(typename Predicate::first_argument_type const& x, typename Predicate::second_argument_type const& y) const {
|
||||
return !fn(x, y);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Predicate>
|
||||
|
|
Loading…
Reference in a new issue