1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2025-10-05 13:00:00 +00:00

fix weed warnings.

add compost library.
This commit is contained in:
bolero-MURAKAMI 2012-11-09 01:09:49 +09:00
commit d01ee064e2
31 changed files with 1566 additions and 120 deletions

View file

@ -1,34 +1,68 @@
#ifndef SPROUT_FUNCTIONAL_BIND1ST_HPP
#define SPROUT_FUNCTIONAL_BIND1ST_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/functional/base.hpp>
#include <sprout/functional/type_traits.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// D.9.1 Class template binder1st
template<typename Fn>
class binder1st
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;
typename Fn::first_argument_type value;
value_type value;
public:
SPROUT_CONSTEXPR binder1st(Fn const& x, typename Fn::first_argument_type const& y)
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 {
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>
SPROUT_CONSTEXPR decltype(op(value, std::declval<U const&>()))
operator()(U const& x) const {
return op(value, x);
}
};
// D.9.2 bind1st
template<typename Fn, typename T>
inline SPROUT_CONSTEXPR sprout::binder1st<Fn>
inline SPROUT_CONSTEXPR sprout::binder1st<Fn, T>
bind1st(Fn const& fn, T const& x) {
return sprout::binder1st<Fn>(fn, typename Fn::first_argument_type(x));
return sprout::binder1st<Fn, T>(fn, typename sprout::binder1st<Fn, T>::value_type(x));
}
} // namespace sprout

View file

@ -8,27 +8,59 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// D.9.3 Class template binder2nd
template<typename Fn>
class 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>
{
public:
typedef typename std::conditional<
std::is_void<T>::value,
typename Fn::second_argument_type,
T
>::type value_type;
protected:
Fn op;
typename Fn::second_argument_type value;
value_type value;
public:
SPROUT_CONSTEXPR binder2nd(Fn const& x, typename Fn::second_argument_type const& y)
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 {
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.4 bind2nd
// D.9.3 bind2nd
template<typename Fn, typename T>
inline SPROUT_CONSTEXPR sprout::binder2nd<Fn>
bind2nd(Fn const& op, T const& x) {
return sprout::binder2nd<Fn>(op, typename Fn::second_argument_type(x));
inline SPROUT_CONSTEXPR sprout::binder2nd<Fn, T>
bind2nd(Fn const& fn, T const& x) {
return sprout::binder2nd<Fn, T>(fn, typename sprout::binder2nd<Fn, T>::value_type(x));
}
} // namespace sprout

View file

@ -0,0 +1,57 @@
#ifndef SPROUT_FUNCTIONAL_TYPE_TRAITS_HPP
#define SPROUT_FUNCTIONAL_TYPE_TRAITS_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/type_traits/has_xxx.hpp>
#include <sprout/type_traits/inherit_if_xxx.hpp>
namespace sprout {
//
// has_result_type
// has_argument_type
// has_first_argument_type
// has_second_argument_type
//
SPROUT_HAS_XXX_TYPE_DEF_LAZY(result_type);
SPROUT_HAS_XXX_TYPE_DEF_LAZY(argument_type);
SPROUT_HAS_XXX_TYPE_DEF_LAZY(first_argument_type);
SPROUT_HAS_XXX_TYPE_DEF_LAZY(second_argument_type);
//
// inhert_if_result_type
// inhert_if_argument_type
// inhert_if_first_argument_type
// inhert_if_second_argument_type
//
SPROUT_INHERIT_IF_XXX_TYPE_DEF_LAZY(result_type);
SPROUT_INHERIT_IF_XXX_TYPE_DEF_LAZY(argument_type);
SPROUT_INHERIT_IF_XXX_TYPE_DEF_LAZY(first_argument_type);
SPROUT_INHERIT_IF_XXX_TYPE_DEF_LAZY(second_argument_type);
//
// is_strict_unary_function
//
template<typename Fn>
struct is_strict_unary_function
: public std::integral_constant<
bool,
sprout::has_result_type<Fn>::value
&& sprout::has_argument_type<Fn>::value
>
{};
//
// is_strict_binary_function
//
template<typename Fn>
struct is_strict_binary_function
: public std::integral_constant<
bool,
sprout::has_result_type<Fn>::value
&& sprout::has_first_argument_type<Fn>::value
&& sprout::has_second_argument_type<Fn>::value
>
{};
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_TYPE_TRAITS_HPP