mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
add bind, mem_fn, ref, and others.
This commit is contained in:
parent
30dbbc44fc
commit
aa4fc785b0
29 changed files with 1564 additions and 18 deletions
|
@ -3,9 +3,11 @@
|
|||
|
||||
#ifndef SPROUT_CONFIG_DISABLE_CONSTEXPR
|
||||
# define SPROUT_CONSTEXPR constexpr
|
||||
# define SPROUT_CONSTEXPR_OR_CONST constexpr
|
||||
# define SPROUT_STATIC_CONSTEXPR static constexpr
|
||||
#else // #ifndef SPROUT_CONFIG_DISABLE_CONSTEXPR
|
||||
# define SPROUT_CONSTEXPR
|
||||
# define SPROUT_CONSTEXPR_OR_CONST const
|
||||
# define SPROUT_STATIC_CONSTEXPR static const
|
||||
#endif // #ifndef SPROUT_CONFIG_DISABLE_CONSTEXPR
|
||||
|
||||
|
@ -30,9 +32,9 @@
|
|||
#endif // #ifndef SPROUT_CONFIG_DISABLE_USER_DEFINED_LITERALS
|
||||
|
||||
#ifndef SPROUT_CONFIG_USE_SSCRISK_CEL
|
||||
# define HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT <sprout/functional.hpp>
|
||||
# define HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT <sprout/functional/functor.hpp>
|
||||
# define HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT <sprout/algorithm/non_modifying.hpp>
|
||||
# define HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT <sprout/iterator.hpp>
|
||||
# define HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT <sprout/iterator/operation.hpp>
|
||||
# define NS_SSCRISK_CEL_OR_SPROUT sprout
|
||||
#else // #ifndef SPROUT_CONFIG_USE_SSCRISK_CEL
|
||||
# define HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT <sscrisk/cel/functional.hpp>
|
||||
|
|
|
@ -2,9 +2,11 @@
|
|||
#define SPROUT_FUNCTIONAL_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/arithmetic.hpp>
|
||||
#include <sprout/functional/comparison.hpp>
|
||||
#include <sprout/functional/bind1st.hpp>
|
||||
#include <sprout/functional/bind2nd.hpp>
|
||||
#include <sprout/functional/base.hpp>
|
||||
#include <sprout/functional/functor.hpp>
|
||||
#include <sprout/functional/ref.hpp>
|
||||
#include <sprout/functional/mem_fn.hpp>
|
||||
#include <sprout/functional/bind.hpp>
|
||||
#include <sprout/functional/hash.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_HPP
|
||||
|
|
8
sprout/functional/base.hpp
Normal file
8
sprout/functional/base.hpp
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_BASE_HPP
|
||||
#define SPROUT_FUNCTIONAL_BASE_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/unary_function.hpp>
|
||||
#include <sprout/functional/binary_function.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_BASE_HPP
|
19
sprout/functional/binary_function.hpp
Normal file
19
sprout/functional/binary_function.hpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_BINARY_FUNCTION_HPP
|
||||
#define SPROUT_FUNCTIONAL_BINARY_FUNCTION_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// binary_function
|
||||
//
|
||||
template<typename Arg1, typename Arg2, typename Result>
|
||||
struct binary_function {
|
||||
public:
|
||||
typedef Arg1 first_argument_type;
|
||||
typedef Arg2 second_argument_type;
|
||||
typedef Result result_type;
|
||||
};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_BINARY_FUNCTION_HPP
|
7
sprout/functional/bind.hpp
Normal file
7
sprout/functional/bind.hpp
Normal file
|
@ -0,0 +1,7 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_BIND_HPP
|
||||
#define SPROUT_FUNCTIONAL_BIND_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/bind/bind.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_BIND_HPP
|
541
sprout/functional/bind/bind.hpp
Normal file
541
sprout/functional/bind/bind.hpp
Normal file
|
@ -0,0 +1,541 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_BIND_BIND_HPP
|
||||
#define SPROUT_FUNCTIONAL_BIND_BIND_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <utility>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/index_tuple.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/utility/lvalue_forward.hpp>
|
||||
#include <sprout/tuple/tuple.hpp>
|
||||
#include <sprout/functional/ref.hpp>
|
||||
#include <sprout/functional/mem_fn.hpp>
|
||||
#include <sprout/functional/weak_result_type.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// 20.8.9 bind
|
||||
|
||||
template<typename T>
|
||||
struct is_bind_expression
|
||||
: public std::false_type
|
||||
{};
|
||||
template<typename T>
|
||||
struct is_bind_expression<T const>
|
||||
: public sprout::is_bind_expression<T>
|
||||
{};
|
||||
|
||||
template<typename T>
|
||||
struct is_placeholder
|
||||
: public std::integral_constant<int, 0>
|
||||
{};
|
||||
template<typename T>
|
||||
struct is_placeholder<T const>
|
||||
: public sprout::is_placeholder<T>
|
||||
{};
|
||||
|
||||
//
|
||||
// placeholder
|
||||
//
|
||||
template<int N>
|
||||
struct placeholder {};
|
||||
|
||||
namespace placeholders {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<1> _1;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<2> _2;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<3> _3;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<4> _4;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<5> _5;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<6> _6;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<7> _7;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<8> _8;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<9> _9;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<10> _10;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<11> _11;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<12> _12;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<13> _13;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<14> _14;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<15> _15;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<16> _16;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<17> _17;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<18> _18;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<19> _19;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<20> _20;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<21> _21;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<22> _22;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<23> _23;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<24> _24;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<25> _25;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<26> _26;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<27> _27;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<28> _28;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<29> _29;
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<30> _30;
|
||||
} // namespace placeholders
|
||||
using sprout::placeholders::_1;
|
||||
using sprout::placeholders::_2;
|
||||
using sprout::placeholders::_3;
|
||||
using sprout::placeholders::_4;
|
||||
using sprout::placeholders::_5;
|
||||
using sprout::placeholders::_6;
|
||||
using sprout::placeholders::_7;
|
||||
using sprout::placeholders::_8;
|
||||
using sprout::placeholders::_9;
|
||||
using sprout::placeholders::_10;
|
||||
using sprout::placeholders::_11;
|
||||
using sprout::placeholders::_12;
|
||||
using sprout::placeholders::_13;
|
||||
using sprout::placeholders::_14;
|
||||
using sprout::placeholders::_15;
|
||||
using sprout::placeholders::_16;
|
||||
using sprout::placeholders::_17;
|
||||
using sprout::placeholders::_18;
|
||||
using sprout::placeholders::_19;
|
||||
using sprout::placeholders::_20;
|
||||
using sprout::placeholders::_21;
|
||||
using sprout::placeholders::_2;
|
||||
using sprout::placeholders::_23;
|
||||
using sprout::placeholders::_24;
|
||||
using sprout::placeholders::_25;
|
||||
using sprout::placeholders::_26;
|
||||
using sprout::placeholders::_27;
|
||||
using sprout::placeholders::_28;
|
||||
using sprout::placeholders::_29;
|
||||
using sprout::placeholders::_30;
|
||||
|
||||
template<int N>
|
||||
struct is_placeholder<sprout::placeholder<N> >
|
||||
: public std::integral_constant<int, N>
|
||||
{};
|
||||
|
||||
namespace detail {
|
||||
struct no_tuple_element;
|
||||
|
||||
template<std::size_t I, typename Tuple, bool IsSafe>
|
||||
struct safe_tuple_element_impl
|
||||
: tuple_element<I, Tuple>
|
||||
{};
|
||||
template<std::size_t I, typename Tuple>
|
||||
struct safe_tuple_element_impl<I, Tuple, false> {
|
||||
public:
|
||||
typedef sprout::detail::no_tuple_element type;
|
||||
};
|
||||
template<std::size_t I, typename Tuple>
|
||||
struct safe_tuple_element
|
||||
: public sprout::detail::safe_tuple_element_impl<I, Tuple, (I < sprout::tuples::tuple_size<Tuple>::value)>
|
||||
{};
|
||||
|
||||
template<
|
||||
typename Arg,
|
||||
bool IsBindExp = sprout::is_bind_expression<Arg>::value,
|
||||
bool IsPlaceholder = (sprout::is_placeholder<Arg>::value > 0)
|
||||
>
|
||||
class mu;
|
||||
template<typename T>
|
||||
class mu<sprout::reference_wrapper<T>, false, false> {
|
||||
public:
|
||||
typedef T& result_type;
|
||||
public:
|
||||
template<typename CVRef, typename Tuple>
|
||||
SPROUT_CONSTEXPR result_type operator()(CVRef& arg, Tuple&) const volatile {
|
||||
// !!!
|
||||
//return arg.get();
|
||||
return const_cast<typename std::remove_volatile<typename std::remove_reference<CVRef>::type>::type&>(arg).get();
|
||||
}
|
||||
};
|
||||
template<typename Arg>
|
||||
class mu<Arg, true, false> {
|
||||
private:
|
||||
template<typename CVArg, typename... Args, sprout::index_t... Indexes>
|
||||
SPROUT_CONSTEXPR auto call(
|
||||
CVArg& arg,
|
||||
sprout::tuples::tuple<Args...>& tuple,
|
||||
sprout::index_tuple<Indexes...>
|
||||
) const volatile
|
||||
-> decltype(arg(std::declval<Args>()...))
|
||||
{
|
||||
return arg(sprout::forward<Args>(sprout::tuples::get<Indexes>(tuple))...);
|
||||
}
|
||||
public:
|
||||
template<typename CVArg, typename... Args>
|
||||
SPROUT_CONSTEXPR auto operator()(CVArg& arg, sprout::tuples::tuple<Args...>& tuple) const volatile
|
||||
-> decltype(arg(std::declval<Args>()...))
|
||||
{
|
||||
return call(arg, tuple, typename sprout::index_range<0, sizeof...(Args)>::type());
|
||||
}
|
||||
};
|
||||
template<typename Arg>
|
||||
class mu<Arg, false, true> {
|
||||
public:
|
||||
template<typename Signature>
|
||||
class result;
|
||||
template<typename CVMu, typename CVArg, typename Tuple>
|
||||
class result<CVMu (CVArg, Tuple)> {
|
||||
private:
|
||||
typedef typename sprout::detail::safe_tuple_element<
|
||||
(sprout::is_placeholder<Arg>::value - 1),
|
||||
Tuple
|
||||
>::type base_type;
|
||||
public:
|
||||
typedef typename std::add_rvalue_reference<base_type>::type type;
|
||||
};
|
||||
public:
|
||||
template<typename Tuple>
|
||||
typename result<mu (Arg, Tuple)>::type
|
||||
SPROUT_CONSTEXPR operator()(Arg const volatile&, Tuple& tuple) const volatile {
|
||||
return sprout::forward<typename result<mu (Arg, Tuple)>::type>(
|
||||
sprout::tuples::get<(sprout::is_placeholder<Arg>::value - 1)>(tuple)
|
||||
);
|
||||
}
|
||||
};
|
||||
template<typename Arg>
|
||||
class mu<Arg, false, false> {
|
||||
public:
|
||||
template<typename Signature>
|
||||
struct result;
|
||||
template<typename CVMu, typename CVArg, typename Tuple>
|
||||
struct result<CVMu (CVArg, Tuple)> {
|
||||
public:
|
||||
typedef typename std::add_lvalue_reference<CVArg>::type type;
|
||||
};
|
||||
public:
|
||||
template<typename CVArg, typename Tuple>
|
||||
SPROUT_CONSTEXPR CVArg&& operator()(CVArg&& arg, Tuple&) const volatile {
|
||||
return sprout::forward<CVArg>(arg);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct maybe_wrap_member_pointer {
|
||||
public:
|
||||
typedef T type;
|
||||
public:
|
||||
static SPROUT_CONSTEXPR T const& do_wrap(T const& x) {
|
||||
return x;
|
||||
}
|
||||
static SPROUT_CONSTEXPR T&& do_wrap(T&& x) {
|
||||
return static_cast<T&&>(x);
|
||||
}
|
||||
};
|
||||
template<typename T, typename Class>
|
||||
struct maybe_wrap_member_pointer<T Class::*> {
|
||||
public:
|
||||
typedef sprout::mem_fn_adaptor<T Class::*> type;
|
||||
public:
|
||||
static SPROUT_CONSTEXPR type do_wrap(T Class::* pm) {
|
||||
return type(pm);
|
||||
}
|
||||
};
|
||||
template<>
|
||||
struct maybe_wrap_member_pointer<void> {
|
||||
public:
|
||||
typedef void type;
|
||||
};
|
||||
|
||||
template<std::size_t I, typename... Types>
|
||||
inline auto volget(sprout::tuples::tuple<Types...> volatile& tuple)
|
||||
-> typename sprout::tuples::tuple_element<I, sprout::tuples::tuple<Types...> >::type volatile&
|
||||
{
|
||||
return sprout::tuples::get<I>(const_cast<sprout::tuples::tuple<Types...>&>(tuple));
|
||||
}
|
||||
template<std::size_t I, typename... Types>
|
||||
inline SPROUT_CONSTEXPR auto volget(sprout::tuples::tuple<Types...> const volatile& tuple)
|
||||
-> typename sprout::tuples::tuple_element<I, sprout::tuples::tuple<Types...> >::type const volatile&
|
||||
{
|
||||
return sprout::tuples::get<I>(const_cast<sprout::tuples::tuple<Types...> const&>(tuple));
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// binder
|
||||
//
|
||||
template<typename Signature>
|
||||
struct binder;
|
||||
template<typename Functor, typename... BoundArgs>
|
||||
class binder<Functor(BoundArgs...)>
|
||||
: public sprout::weak_result_type<Functor>
|
||||
{
|
||||
private:
|
||||
typedef binder self_type;
|
||||
typedef typename sprout::index_range<0, sizeof...(BoundArgs)>::type bound_indexes;
|
||||
private:
|
||||
Functor f_;
|
||||
sprout::tuples::tuple<BoundArgs...> bound_args_;
|
||||
private:
|
||||
template<typename Result, typename... Args, sprout::index_t... Indexes>
|
||||
Result call(sprout::tuples::tuple<Args...>&& args, sprout::index_tuple<Indexes...>) {
|
||||
return f_(sprout::detail::mu<BoundArgs>()(sprout::tuples::get<Indexes>(bound_args_), args)...);
|
||||
}
|
||||
template<typename Result, typename... Args, sprout::index_t... Indexes>
|
||||
SPROUT_CONSTEXPR Result call_c(sprout::tuples::tuple<Args...>&& args, sprout::index_tuple<Indexes...>) const {
|
||||
return f_(sprout::detail::mu<BoundArgs>()(sprout::tuples::get<Indexes>(bound_args_), args)...);
|
||||
}
|
||||
template<typename Result, typename... Args, sprout::index_t... Indexes>
|
||||
Result call_v(sprout::tuples::tuple<Args...>&& args, sprout::index_tuple<Indexes...>) volatile {
|
||||
return f_(sprout::detail::mu<BoundArgs>()(sprout::detail::volget<Indexes>(bound_args_), args)...);
|
||||
}
|
||||
template<typename Result, typename... Args, sprout::index_t... Indexes>
|
||||
SPROUT_CONSTEXPR Result call_cv(sprout::tuples::tuple<Args...>&& args, sprout::index_tuple<Indexes...>) const volatile {
|
||||
return f_(sprout::detail::mu<BoundArgs>()(sprout::detail::volget<Indexes>(bound_args_), args)...);
|
||||
}
|
||||
public:
|
||||
template<typename... Args>
|
||||
explicit SPROUT_CONSTEXPR binder(Functor const& f, Args&&... args)
|
||||
: f_(f)
|
||||
, bound_args_(sprout::forward<Args>(args)...)
|
||||
{}
|
||||
binder(binder const&) = default;
|
||||
template<
|
||||
typename... Args,
|
||||
typename Result = decltype(
|
||||
std::declval<Functor>()(
|
||||
sprout::detail::mu<BoundArgs>()(
|
||||
std::declval<BoundArgs&>(),
|
||||
std::declval<sprout::tuples::tuple<Args...>&>()
|
||||
)...
|
||||
)
|
||||
)
|
||||
>
|
||||
Result operator()(Args&&... args) {
|
||||
return call<Result>(
|
||||
sprout::tuples::forward_as_tuple(sprout::forward<Args>(args)...),
|
||||
bound_indexes()
|
||||
);
|
||||
}
|
||||
template<
|
||||
typename... Args,
|
||||
typename Result = decltype(
|
||||
std::declval<typename std::enable_if<(sizeof...(Args) >= 0), typename std::add_const<Functor>::type>::type>()(
|
||||
sprout::detail::mu<BoundArgs>()(
|
||||
std::declval<BoundArgs const&>(),
|
||||
std::declval<sprout::tuples::tuple<Args...>&>()
|
||||
)...
|
||||
)
|
||||
)
|
||||
>
|
||||
SPROUT_CONSTEXPR Result operator()(Args&&... args) const {
|
||||
return call_c<Result>(
|
||||
sprout::tuples::forward_as_tuple(sprout::forward<Args>(args)...),
|
||||
bound_indexes()
|
||||
);
|
||||
}
|
||||
template<
|
||||
typename... Args,
|
||||
typename Result = decltype(
|
||||
std::declval<typename std::enable_if<(sizeof...(Args) >= 0), typename std::add_volatile<Functor>::type>::type>()(
|
||||
sprout::detail::mu<BoundArgs>()(
|
||||
std::declval<BoundArgs volatile&>(),
|
||||
std::declval<sprout::tuples::tuple<Args...>&>()
|
||||
)...
|
||||
)
|
||||
)
|
||||
>
|
||||
Result operator()(Args&&... args) volatile {
|
||||
return call_v<Result>(
|
||||
sprout::tuples::forward_as_tuple(sprout::forward<Args>(args)...),
|
||||
bound_indexes()
|
||||
);
|
||||
}
|
||||
|
||||
template<
|
||||
typename... Args,
|
||||
typename Result = decltype(
|
||||
std::declval<typename std::enable_if<(sizeof...(Args) >= 0), typename std::add_cv<Functor>::type>::type>()(
|
||||
sprout::detail::mu<BoundArgs>()(
|
||||
std::declval<BoundArgs const volatile&>(),
|
||||
std::declval<sprout::tuples::tuple<Args...>&>()
|
||||
)...
|
||||
)
|
||||
)
|
||||
>
|
||||
SPROUT_CONSTEXPR Result operator()(Args&&... args) const volatile {
|
||||
return call_cv<Result>(
|
||||
sprout::tuples::forward_as_tuple(sprout::forward<Args>(args)...),
|
||||
bound_indexes()
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// bind_result
|
||||
//
|
||||
template<typename Result, typename Signature>
|
||||
struct bind_result;
|
||||
template<typename Result, typename Functor, typename... BoundArgs>
|
||||
class bind_result<Result, Functor(BoundArgs...)> {
|
||||
private:
|
||||
typedef bind_result self_type;
|
||||
typedef typename sprout::index_range<0, sizeof...(BoundArgs)>::type bound_indexes;
|
||||
private:
|
||||
template<typename Res>
|
||||
struct enable_if_void
|
||||
: public std::enable_if<std::is_void<Res>::value, int>
|
||||
{};
|
||||
template<typename Res>
|
||||
struct disable_if_void
|
||||
: public std::enable_if<!std::is_void<Res>::value, int>
|
||||
{};
|
||||
private:
|
||||
Functor f_;
|
||||
sprout::tuples::tuple<BoundArgs...> bound_args_;
|
||||
private:
|
||||
template<typename Res, typename... Args, sprout::index_t... Indexes>
|
||||
Result call(
|
||||
sprout::tuples::tuple<Args...>&& args,
|
||||
sprout::index_tuple<Indexes...>,
|
||||
typename disable_if_void<Res>::type = 0
|
||||
)
|
||||
{
|
||||
return f_(sprout::detail::mu<BoundArgs>()(sprout::tuples::get<Indexes>(bound_args_), args)...);
|
||||
}
|
||||
template<typename Res, typename... Args, sprout::index_t... Indexes>
|
||||
Result call(
|
||||
sprout::tuples::tuple<Args...>&& args,
|
||||
sprout::index_tuple<Indexes...>,
|
||||
typename enable_if_void<Res>::type = 0
|
||||
)
|
||||
{
|
||||
f_(sprout::detail::mu<BoundArgs>()(get<Indexes>(bound_args_), args)...);
|
||||
}
|
||||
template<typename Res, typename... Args, sprout::index_t... Indexes>
|
||||
SPROUT_CONSTEXPR Result call(
|
||||
sprout::tuples::tuple<Args...>&& args,
|
||||
sprout::index_tuple<Indexes...>,
|
||||
typename disable_if_void<Res>::type = 0
|
||||
) const
|
||||
{
|
||||
return f_(sprout::detail::mu<BoundArgs>()(sprout::tuples::get<Indexes>(bound_args_), args)...);
|
||||
}
|
||||
template<typename Res, typename... Args, sprout::index_t... Indexes>
|
||||
Result call(
|
||||
sprout::tuples::tuple<Args...>&& args,
|
||||
sprout::index_tuple<Indexes...>,
|
||||
typename enable_if_void<Res>::type = 0
|
||||
) const
|
||||
{
|
||||
f_(sprout::detail::mu<BoundArgs>()(sprout::tuples::get<Indexes>(bound_args_), args)...);
|
||||
}
|
||||
template<typename Res, typename... Args, sprout::index_t... Indexes>
|
||||
Result call(
|
||||
sprout::tuples::tuple<Args...>&& args,
|
||||
sprout::index_tuple<Indexes...>,
|
||||
typename disable_if_void<Res>::type = 0
|
||||
) volatile
|
||||
{
|
||||
return f_(sprout::detail::mu<BoundArgs>()(sprout::detail::volget<Indexes>(bound_args_), args)...);
|
||||
}
|
||||
template<typename Res, typename... Args, sprout::index_t... Indexes>
|
||||
Result call(
|
||||
sprout::tuples::tuple<Args...>&& args,
|
||||
sprout::index_tuple<Indexes...>,
|
||||
typename enable_if_void<Res>::type = 0
|
||||
) volatile
|
||||
{
|
||||
f_(sprout::detail::mu<BoundArgs>()(sprout::detail::volget<Indexes>(bound_args_), args)...);
|
||||
}
|
||||
template<typename Res, typename... Args, sprout::index_t... Indexes>
|
||||
SPROUT_CONSTEXPR Result call(
|
||||
sprout::tuples::tuple<Args...>&& args,
|
||||
sprout::index_tuple<Indexes...>,
|
||||
typename disable_if_void<Res>::type = 0
|
||||
) const volatile
|
||||
{
|
||||
return f_(sprout::detail::mu<BoundArgs>()(sprout::detail::volget<Indexes>(bound_args_), args)...);
|
||||
}
|
||||
template<typename Res, typename... Args, sprout::index_t... Indexes>
|
||||
Result call(
|
||||
sprout::tuples::tuple<Args...>&& args,
|
||||
sprout::index_tuple<Indexes...>,
|
||||
typename enable_if_void<Res>::type = 0
|
||||
) const volatile
|
||||
{
|
||||
f_(sprout::detail::mu<BoundArgs>()(sprout::detail::volget<Indexes>(bound_args_), args)...);
|
||||
}
|
||||
public:
|
||||
typedef Result result_type;
|
||||
template<typename... Args>
|
||||
explicit bind_result(Functor const& f, Args&&... args)
|
||||
: f_(f)
|
||||
, bound_args_(sprout::forward<Args>(args)...)
|
||||
{}
|
||||
bind_result(bind_result const&) = default;
|
||||
template<typename... Args>
|
||||
result_type operator()(Args&&... args) {
|
||||
return call<Result>(
|
||||
sprout::tuples::forward_as_tuple(sprout::forward<Args>(args)...),
|
||||
bound_indexes()
|
||||
);
|
||||
}
|
||||
template<typename... Args>
|
||||
SPROUT_CONSTEXPR result_type operator()(Args&&... args) const {
|
||||
return call<Result>(
|
||||
sprout::tuples::forward_as_tuple(sprout::forward<Args>(args)...),
|
||||
bound_indexes()
|
||||
);
|
||||
}
|
||||
template<typename... Args>
|
||||
result_type operator()(Args&&... args) volatile {
|
||||
return call<Result>(
|
||||
sprout::tuples::forward_as_tuple(sprout::forward<Args>(args)...),
|
||||
bound_indexes()
|
||||
);
|
||||
}
|
||||
template<typename... Args>
|
||||
SPROUT_CONSTEXPR result_type operator()(Args&&... args) const volatile {
|
||||
return call<Result>(
|
||||
sprout::tuples::forward_as_tuple(sprout::forward<Args>(args)...),
|
||||
bound_indexes()
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Signature>
|
||||
struct is_bind_expression<sprout::binder<Signature> >
|
||||
: public std::true_type
|
||||
{};
|
||||
template<typename Result, typename Signature>
|
||||
struct is_bind_expression<sprout::bind_result<Result, Signature> >
|
||||
: public std::true_type
|
||||
{};
|
||||
|
||||
namespace detail {
|
||||
template<typename Func, typename... BoundArgs>
|
||||
struct bind_helper {
|
||||
public:
|
||||
typedef sprout::detail::maybe_wrap_member_pointer<typename std::decay<Func>::type> maybe_type;
|
||||
typedef typename maybe_type::type func_type;
|
||||
typedef sprout::binder<func_type (typename std::decay<BoundArgs>::type...)> type;
|
||||
};
|
||||
|
||||
template<typename Result, typename Func, typename... BoundArgs>
|
||||
struct bindres_helper {
|
||||
public:
|
||||
typedef sprout::detail::maybe_wrap_member_pointer<typename std::decay<Func>::type> maybe_type;
|
||||
typedef typename maybe_type::type functor_type;
|
||||
typedef sprout::bind_result<Result, functor_type (typename std::decay<BoundArgs>::type...)> type;
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// bind
|
||||
//
|
||||
template<typename F, typename... BoundArgs>
|
||||
inline SPROUT_CONSTEXPR typename sprout::detail::bind_helper<F, BoundArgs...>::type
|
||||
bind(F&& f, BoundArgs&&... args) {
|
||||
typedef sprout::detail::bind_helper<F, BoundArgs...> helper_type;
|
||||
typedef typename helper_type::maybe_type maybe_type;
|
||||
typedef typename helper_type::type result_type;
|
||||
return result_type(maybe_type::do_wrap(sprout::forward<F>(f)), sprout::forward<BoundArgs>(args)...);
|
||||
}
|
||||
template<typename R, typename F, typename... BoundArgs>
|
||||
inline SPROUT_CONSTEXPR typename sprout::detail::bindres_helper<R, F, BoundArgs...>::type
|
||||
bind(F&& f, BoundArgs&&... args) {
|
||||
typedef sprout::detail::bindres_helper<R, F, BoundArgs...> helper_type;
|
||||
typedef typename helper_type::maybe_type maybe_type;
|
||||
typedef typename helper_type::type result_type;
|
||||
return result_type(maybe_type::do_wrap(sprout::forward<F>(f)), sprout::forward<BoundArgs>(args)...);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_BIND_BIND_HPP
|
8
sprout/functional/binder.hpp
Normal file
8
sprout/functional/binder.hpp
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_BINDER_HPP
|
||||
#define SPROUT_FUNCTIONAL_BINDER_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/bind1st.hpp>
|
||||
#include <sprout/functional/bind2nd.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_BINDER_HPP
|
21
sprout/functional/bit_and.hpp
Normal file
21
sprout/functional/bit_and.hpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_BIT_AND_HPP
|
||||
#define SPROUT_FUNCTIONAL_BIT_AND_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// 20.8.7 bitwise operations
|
||||
template<typename T>
|
||||
struct bit_and {
|
||||
public:
|
||||
typedef T first_argument_type;
|
||||
typedef T second_argument_type;
|
||||
typedef T result_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR T operator()(T const& x, T const& y) const {
|
||||
return x & y;
|
||||
}
|
||||
};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_BIT_AND_HPP
|
20
sprout/functional/bit_not.hpp
Normal file
20
sprout/functional/bit_not.hpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_BIT_NOT_HPP
|
||||
#define SPROUT_FUNCTIONAL_BIT_NOT_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// 20.8.7 bitwise operations
|
||||
template<typename T>
|
||||
struct bit_not {
|
||||
public:
|
||||
typedef T argument_type;
|
||||
typedef T result_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR T operator()(T const& x) const {
|
||||
return !x;
|
||||
}
|
||||
};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_BIT_NOT_HPP
|
21
sprout/functional/bit_or.hpp
Normal file
21
sprout/functional/bit_or.hpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_BIT_OR_HPP
|
||||
#define SPROUT_FUNCTIONAL_BIT_OR_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// 20.8.7 bitwise operations
|
||||
template<typename T>
|
||||
struct bit_or {
|
||||
public:
|
||||
typedef T first_argument_type;
|
||||
typedef T second_argument_type;
|
||||
typedef T result_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR T operator()(T const& x, T const& y) const {
|
||||
return x | y;
|
||||
}
|
||||
};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_BIT_OR_HPP
|
21
sprout/functional/bit_xor.hpp
Normal file
21
sprout/functional/bit_xor.hpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_BIT_XOR_HPP
|
||||
#define SPROUT_FUNCTIONAL_BIT_XOR_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// 20.8.7 bitwise operations
|
||||
template<typename T>
|
||||
struct bit_xor {
|
||||
public:
|
||||
typedef T first_argument_type;
|
||||
typedef T second_argument_type;
|
||||
typedef T result_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR T operator()(T const& x, T const& y) const {
|
||||
return x ^ y;
|
||||
}
|
||||
};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_BIT_XOR_HPP
|
9
sprout/functional/bitwise.hpp
Normal file
9
sprout/functional/bitwise.hpp
Normal file
|
@ -0,0 +1,9 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_BITWISE_HPP
|
||||
#define SPROUT_FUNCTIONAL_BITWISE_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/bit_and.hpp>
|
||||
#include <sprout/functional/bit_or.hpp>
|
||||
#include <sprout/functional/bit_xor.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_BITWISE_HPP
|
12
sprout/functional/functor.hpp
Normal file
12
sprout/functional/functor.hpp
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_FUNCTOR_HPP
|
||||
#define SPROUT_FUNCTIONAL_FUNCTOR_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/arithmetic.hpp>
|
||||
#include <sprout/functional/comparison.hpp>
|
||||
#include <sprout/functional/logical.hpp>
|
||||
#include <sprout/functional/bitwise.hpp>
|
||||
#include <sprout/functional/binder.hpp>
|
||||
#include <sprout/functional/negator.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_FUNCTOR_HPP
|
|
@ -13,9 +13,11 @@ namespace sprout {
|
|||
//
|
||||
inline SPROUT_CONSTEXPR std::size_t hash_value(bool v);
|
||||
inline SPROUT_CONSTEXPR std::size_t hash_value(char v);
|
||||
inline SPROUT_CONSTEXPR std::size_t hash_value(wchar_t v);
|
||||
inline SPROUT_CONSTEXPR std::size_t hash_value(unsigned char v);
|
||||
inline SPROUT_CONSTEXPR std::size_t hash_value(signed char v);
|
||||
inline SPROUT_CONSTEXPR std::size_t hash_value(char16_t v);
|
||||
inline SPROUT_CONSTEXPR std::size_t hash_value(char32_t v);
|
||||
inline SPROUT_CONSTEXPR std::size_t hash_value(wchar_t v);
|
||||
inline SPROUT_CONSTEXPR std::size_t hash_value(short v);
|
||||
inline SPROUT_CONSTEXPR std::size_t hash_value(unsigned short v);
|
||||
inline SPROUT_CONSTEXPR std::size_t hash_value(int v);
|
||||
|
@ -103,15 +105,21 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR std::size_t hash_value(char v) {
|
||||
return static_cast<std::size_t>(v);
|
||||
}
|
||||
inline SPROUT_CONSTEXPR std::size_t hash_value(wchar_t v) {
|
||||
return static_cast<std::size_t>(v);
|
||||
}
|
||||
inline SPROUT_CONSTEXPR std::size_t hash_value(unsigned char v) {
|
||||
return static_cast<std::size_t>(v);
|
||||
}
|
||||
inline SPROUT_CONSTEXPR std::size_t hash_value(signed char v) {
|
||||
return static_cast<std::size_t>(v);
|
||||
}
|
||||
inline SPROUT_CONSTEXPR std::size_t hash_value(char16_t v) {
|
||||
return static_cast<std::size_t>(v);
|
||||
}
|
||||
inline SPROUT_CONSTEXPR std::size_t hash_value(char32_t v) {
|
||||
return static_cast<std::size_t>(v);
|
||||
}
|
||||
inline SPROUT_CONSTEXPR std::size_t hash_value(wchar_t v) {
|
||||
return static_cast<std::size_t>(v);
|
||||
}
|
||||
inline SPROUT_CONSTEXPR std::size_t hash_value(short v) {
|
||||
return static_cast<std::size_t>(v);
|
||||
}
|
||||
|
@ -216,9 +224,11 @@ namespace sprout {
|
|||
|
||||
SPROUT_HASH_SPECIALIZE(bool);
|
||||
SPROUT_HASH_SPECIALIZE(char);
|
||||
SPROUT_HASH_SPECIALIZE(wchar_t);
|
||||
SPROUT_HASH_SPECIALIZE(signed char);
|
||||
SPROUT_HASH_SPECIALIZE(unsigned char);
|
||||
SPROUT_HASH_SPECIALIZE(char16_t);
|
||||
SPROUT_HASH_SPECIALIZE(char32_t);
|
||||
SPROUT_HASH_SPECIALIZE(wchar_t);
|
||||
SPROUT_HASH_SPECIALIZE(short);
|
||||
SPROUT_HASH_SPECIALIZE(unsigned short);
|
||||
SPROUT_HASH_SPECIALIZE(int);
|
||||
|
|
9
sprout/functional/logical.hpp
Normal file
9
sprout/functional/logical.hpp
Normal file
|
@ -0,0 +1,9 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_LOGICAL_HPP
|
||||
#define SPROUT_FUNCTIONAL_LOGICAL_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/logical_and.hpp>
|
||||
#include <sprout/functional/logical_or.hpp>
|
||||
#include <sprout/functional/logical_not.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_LOGICAL_HPP
|
21
sprout/functional/logical_and.hpp
Normal file
21
sprout/functional/logical_and.hpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_LOGICAL_AND_HPP
|
||||
#define SPROUT_FUNCTIONAL_LOGICAL_AND_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// 20.8.6 logical operations
|
||||
template<typename T>
|
||||
struct logical_and {
|
||||
public:
|
||||
typedef T first_argument_type;
|
||||
typedef T second_argument_type;
|
||||
typedef bool result_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR bool operator()(T const& x, T const& y) const {
|
||||
return x && y;
|
||||
}
|
||||
};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_LOGICAL_AND_HPP
|
20
sprout/functional/logical_not.hpp
Normal file
20
sprout/functional/logical_not.hpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_LOGICAL_NOT_HPP
|
||||
#define SPROUT_FUNCTIONAL_LOGICAL_NOT_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// 20.8.6 logical operations
|
||||
template<typename T>
|
||||
struct logical_not {
|
||||
public:
|
||||
typedef T argument_type;
|
||||
typedef bool result_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR bool operator()(T const& x) const {
|
||||
return !x;
|
||||
}
|
||||
};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_LOGICAL_NOT_HPP
|
21
sprout/functional/logical_or.hpp
Normal file
21
sprout/functional/logical_or.hpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_LOGICAL_OR_HPP
|
||||
#define SPROUT_FUNCTIONAL_LOGICAL_OR_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// 20.8.6 logical operations
|
||||
template<typename T>
|
||||
struct logical_or {
|
||||
public:
|
||||
typedef T first_argument_type;
|
||||
typedef T second_argument_type;
|
||||
typedef bool result_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR bool operator()(T const& x, T const& y) const {
|
||||
return x || y;
|
||||
}
|
||||
};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_LOGICAL_OR_HPP
|
268
sprout/functional/mem_fn.hpp
Normal file
268
sprout/functional/mem_fn.hpp
Normal file
|
@ -0,0 +1,268 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_MEM_FN_HPP
|
||||
#define SPROUT_FUNCTIONAL_MEM_FN_HPP
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// 20.8.10 member function adaptors
|
||||
|
||||
namespace detail {
|
||||
template<typename Res, typename... Args>
|
||||
struct maybe_unary_or_binary_function {};
|
||||
template<typename Res, typename T1>
|
||||
struct maybe_unary_or_binary_function<Res, T1>
|
||||
: public std::unary_function<T1, Res>
|
||||
{};
|
||||
template<typename Res, typename T1, typename T2>
|
||||
struct maybe_unary_or_binary_function<Res, T1, T2>
|
||||
: public std::binary_function<T1, T2, Res>
|
||||
{};
|
||||
|
||||
template<typename T, bool>
|
||||
struct mem_fn_const_or_non {
|
||||
public:
|
||||
typedef T const& type;
|
||||
};
|
||||
template<typename T>
|
||||
struct mem_fn_const_or_non<T, false> {
|
||||
public:
|
||||
typedef T& type;
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// mem_fn_adaptor
|
||||
//
|
||||
template<typename MemberPointer>
|
||||
class mem_fn_adaptor;
|
||||
template<typename Res, typename Class, typename... Args>
|
||||
class mem_fn_adaptor<Res (Class::*)(Args...)>
|
||||
: public sprout::detail::maybe_unary_or_binary_function<Res, Class*, Args...>
|
||||
{
|
||||
public:
|
||||
typedef Res result_type;
|
||||
private:
|
||||
typedef Res (Class::*functor)(Args...);
|
||||
private:
|
||||
functor pmf_;
|
||||
private:
|
||||
template<typename T>
|
||||
Res call(T& object, Class const volatile*, Args... args) const {
|
||||
return (object.*pmf_)(sprout::forward<Args>(args)...);
|
||||
}
|
||||
template<typename T>
|
||||
Res call(T& ptr, void const volatile*, Args... args) const {
|
||||
return ((*ptr).*pmf_)(sprout::forward<Args>(args)...);
|
||||
}
|
||||
public:
|
||||
explicit SPROUT_CONSTEXPR mem_fn_adaptor(functor pmf)
|
||||
: pmf_(pmf)
|
||||
{}
|
||||
Res operator()(Class& object, Args... args) const {
|
||||
return (object.*pmf_)(sprout::forward<Args>(args)...);
|
||||
}
|
||||
Res operator()(Class* object, Args... args) const {
|
||||
return (object->*pmf_)(sprout::forward<Args>(args)...);
|
||||
}
|
||||
template<typename T>
|
||||
Res operator()(T& object, Args... args) const {
|
||||
return call(object, &object, sprout::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
template<typename Res, typename Class, typename... Args>
|
||||
class mem_fn_adaptor<Res (Class::*)(Args...) const>
|
||||
: public sprout::detail::maybe_unary_or_binary_function<Res, Class const*, Args...>
|
||||
{
|
||||
public:
|
||||
typedef Res result_type;
|
||||
private:
|
||||
typedef Res (Class::*functor)(Args...) const;
|
||||
private:
|
||||
functor pmf_;
|
||||
private:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR Res call(T const& object, Class const volatile*, Args... args) const {
|
||||
return (object.*pmf_)(sprout::forward<Args>(args)...);
|
||||
}
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR Res call(T const& ptr, void const volatile*, Args... args) const {
|
||||
return ((*ptr).*pmf_)(sprout::forward<Args>(args)...);
|
||||
}
|
||||
public:
|
||||
explicit SPROUT_CONSTEXPR mem_fn_adaptor(functor pmf)
|
||||
: pmf_(pmf)
|
||||
{}
|
||||
SPROUT_CONSTEXPR Res operator()(Class const& object, Args... args) const {
|
||||
return (object.*pmf_)(sprout::forward<Args>(args)...);
|
||||
}
|
||||
SPROUT_CONSTEXPR Res operator()(Class const* object, Args... args) const {
|
||||
return (object->*pmf_)(sprout::forward<Args>(args)...);
|
||||
}
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR Res operator()(T const& object, Args... args) const {
|
||||
return call(object, &object, sprout::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
template<typename Res, typename Class, typename... Args>
|
||||
class mem_fn_adaptor<Res (Class::*)(Args...) volatile>
|
||||
: public sprout::detail::maybe_unary_or_binary_function<Res, Class volatile*, Args...>
|
||||
{
|
||||
public:
|
||||
typedef Res result_type;
|
||||
private:
|
||||
typedef Res (Class::*functor)(Args...) volatile;
|
||||
private:
|
||||
functor pmf_;
|
||||
private:
|
||||
template<typename T>
|
||||
Res call(T& object, Class const volatile*, Args... args) const {
|
||||
return (object.*pmf_)(sprout::forward<Args>(args)...);
|
||||
}
|
||||
template<typename T>
|
||||
Res call(T& ptr, void const volatile*, Args... args) const {
|
||||
return ((*ptr).*pmf_)(sprout::forward<Args>(args)...);
|
||||
}
|
||||
public:
|
||||
explicit SPROUT_CONSTEXPR mem_fn_adaptor(functor pmf)
|
||||
: pmf_(pmf)
|
||||
{}
|
||||
Res operator()(Class volatile& object, Args... args) const {
|
||||
return (object.*pmf_)(sprout::forward<Args>(args)...);
|
||||
}
|
||||
Res operator()(Class volatile* object, Args... args) const {
|
||||
return (object->*pmf_)(sprout::forward<Args>(args)...);
|
||||
}
|
||||
template<typename T>
|
||||
Res operator()(T& object, Args... args) const {
|
||||
return call(object, &object, sprout::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
template<typename Res, typename Class, typename... Args>
|
||||
class mem_fn_adaptor<Res (Class::*)(Args...) const volatile>
|
||||
: public sprout::detail::maybe_unary_or_binary_function<Res, Class const volatile*, Args...>
|
||||
{
|
||||
public:
|
||||
typedef Res result_type;
|
||||
private:
|
||||
typedef Res (Class::*functor)(Args...) const volatile;
|
||||
private:
|
||||
functor pmf_;
|
||||
private:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR Res call(T const& object, Class const volatile*, Args... args) const {
|
||||
return (object.*pmf_)(sprout::forward<Args>(args)...);
|
||||
}
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR Res call(T const& ptr, void const volatile*, Args... args) const {
|
||||
return ((*ptr).*pmf_)(sprout::forward<Args>(args)...);
|
||||
}
|
||||
public:
|
||||
explicit SPROUT_CONSTEXPR mem_fn_adaptor(functor pmf)
|
||||
: pmf_(pmf)
|
||||
{}
|
||||
SPROUT_CONSTEXPR Res operator()(Class const volatile& object, Args... args) const {
|
||||
return (object.*pmf_)(sprout::forward<Args>(args)...);
|
||||
}
|
||||
SPROUT_CONSTEXPR Res operator()(Class const volatile* object, Args... args) const {
|
||||
return (object->*pmf_)(sprout::forward<Args>(args)...);
|
||||
}
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR Res operator()(T const& object, Args... args) const {
|
||||
return call(object, &object, sprout::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Res, typename Class>
|
||||
class mem_fn_adaptor<Res Class::*> {
|
||||
private:
|
||||
typedef char one;
|
||||
struct two { char v[2]; };
|
||||
private:
|
||||
template<typename T>
|
||||
static T& get_ref();
|
||||
template<typename T>
|
||||
static one check_const(T&, Class*);
|
||||
template<typename T, typename Up>
|
||||
static one check_const(T&, Up* const*);
|
||||
template<typename T, typename Up>
|
||||
static two check_const(T&, Up const* const*);
|
||||
template<typename T>
|
||||
static two check_const(T&, Class const*);
|
||||
template<typename T>
|
||||
static two check_const(T&, const volatile void*);
|
||||
public:
|
||||
template<typename T>
|
||||
struct result_type
|
||||
: public sprout::detail::mem_fn_const_or_non<
|
||||
Res,
|
||||
(sizeof(two) == sizeof(check_const<T>(get_ref<T>(), (T*)0)))
|
||||
>
|
||||
{};
|
||||
template<typename Signature>
|
||||
struct result;
|
||||
template<typename CVMem, typename T>
|
||||
struct result<CVMem(T)>
|
||||
: public result_type<T>
|
||||
{};
|
||||
template<typename CVMem, typename T>
|
||||
struct result<CVMem(T&)>
|
||||
: public result_type<T>
|
||||
{};
|
||||
private:
|
||||
Res Class::* pm_;
|
||||
private:
|
||||
template<typename T>
|
||||
Res& call(T& object, Class*) const {
|
||||
return object.*pm_;
|
||||
}
|
||||
template<typename T, typename Up>
|
||||
Res& call(T& object, Up* const*) const {
|
||||
return (*object).*pm_;
|
||||
}
|
||||
template<typename T, typename Up>
|
||||
const Res& call(T& object, Up const* const*) const {
|
||||
return (*object).*pm_;
|
||||
}
|
||||
template<typename T>
|
||||
Res const& call(T& object, Class const*) const {
|
||||
return object.*pm_;
|
||||
}
|
||||
template<typename T>
|
||||
const Res& call(T& ptr, void const volatile*) const {
|
||||
return (*ptr).*pm_;
|
||||
}
|
||||
public:
|
||||
explicit SPROUT_CONSTEXPR mem_fn_adaptor(Res Class::* pm)
|
||||
: pm_(pm)
|
||||
{}
|
||||
Res& operator()(Class& object) const {
|
||||
return object.*pm_;
|
||||
}
|
||||
SPROUT_CONSTEXPR Res const& operator()(Class const& object) const {
|
||||
return object.*pm_;
|
||||
}
|
||||
Res& operator()(Class* object) const {
|
||||
return object->*pm_;
|
||||
}
|
||||
SPROUT_CONSTEXPR Res const& operator()(Class const* object) const {
|
||||
return object->*pm_;
|
||||
}
|
||||
template<typename T>
|
||||
typename result_type<T>::type operator()(T& unknown) const {
|
||||
return call(unknown, &unknown);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// mem_fn
|
||||
//
|
||||
template<typename T, typename Class>
|
||||
inline SPROUT_CONSTEXPR sprout::mem_fn_adaptor<T Class::*> mem_fn(T Class::* pm) {
|
||||
return sprout::mem_fn_adaptor<T Class::*>(pm);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_MEM_FN_HPP
|
8
sprout/functional/negator.hpp
Normal file
8
sprout/functional/negator.hpp
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_NEGATOR_HPP
|
||||
#define SPROUT_FUNCTIONAL_NEGATOR_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/not1.hpp>
|
||||
#include <sprout/functional/not2.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_NEGATOR_HPP
|
31
sprout/functional/not1.hpp
Normal file
31
sprout/functional/not1.hpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_NOT1_HPP
|
||||
#define SPROUT_FUNCTIONAL_NOT1_HPP
|
||||
|
||||
#include <functional>
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// 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;
|
||||
public:
|
||||
explicit SPROUT_CONSTEXPR unary_negate(Predicate const& pred)
|
||||
: fn(pred)
|
||||
{}
|
||||
SPROUT_CONSTEXPR bool operator()(typename Predicate::argument_type const& x) const {
|
||||
return !fn(x);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Predicate>
|
||||
inline SPROUT_CONSTEXPR sprout::unary_negate<Predicate> not1(Predicate const& pred) {
|
||||
return sprout::unary_negate<Predicate>(pred);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_NOT1_HPP
|
32
sprout/functional/not2.hpp
Normal file
32
sprout/functional/not2.hpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_NOT2_HPP
|
||||
#define SPROUT_FUNCTIONAL_NOT2_HPP
|
||||
|
||||
#include <functional>
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// 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;
|
||||
public:
|
||||
explicit SPROUT_CONSTEXPR binary_negate(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>
|
||||
inline SPROUT_CONSTEXPR sprout::binary_negate<Predicate> not2(Predicate const& pred) {
|
||||
return sprout::binary_negate<Predicate>(pred);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_NOT2_HPP
|
262
sprout/functional/ref.hpp
Normal file
262
sprout/functional/ref.hpp
Normal file
|
@ -0,0 +1,262 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_REF_HPP
|
||||
#define SPROUT_FUNCTIONAL_REF_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/type_traits/has_xxx.hpp>
|
||||
#include <sprout/type_traits/inherit_if_xxx.hpp>
|
||||
#include <sprout/functional/base.hpp>
|
||||
#include <sprout/functional/weak_result_type.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// 20.8.3 reference_wrapper
|
||||
|
||||
namespace detail {
|
||||
template<bool Unary, bool Binary, typename T>
|
||||
struct reference_wrapper_base_impl;
|
||||
template<typename T>
|
||||
struct reference_wrapper_base_impl<false, false, T>
|
||||
: public sprout::weak_result_type<T>
|
||||
{};
|
||||
template<typename T>
|
||||
struct reference_wrapper_base_impl<true, false, T>
|
||||
: public sprout::weak_result_type<T>
|
||||
{
|
||||
public:
|
||||
typedef typename T::argument_type argument_type;
|
||||
};
|
||||
template<typename T>
|
||||
struct reference_wrapper_base_impl<false, true, T>
|
||||
: public sprout::weak_result_type<T>
|
||||
{
|
||||
public:
|
||||
typedef typename T::first_argument_type first_argument_type;
|
||||
typedef typename T::second_argument_type second_argument_type;
|
||||
};
|
||||
template<typename T>
|
||||
struct reference_wrapper_base_impl<true, true, T>
|
||||
: public sprout::weak_result_type<T>
|
||||
{
|
||||
public:
|
||||
typedef typename T::argument_type argument_type;
|
||||
typedef typename T::first_argument_type first_argument_type;
|
||||
typedef typename T::second_argument_type second_argument_type;
|
||||
};
|
||||
template<typename T>
|
||||
struct reference_wrapper_base
|
||||
: public sprout::detail::reference_wrapper_base_impl<
|
||||
sprout::detail::has_argument_type<T>::value,
|
||||
sprout::detail::has_first_argument_type<T>::value
|
||||
&& sprout::detail::has_second_argument_type<T>::value
|
||||
,
|
||||
T
|
||||
>
|
||||
{};
|
||||
template<typename Res, typename T1>
|
||||
struct reference_wrapper_base<Res(T1)>
|
||||
: public sprout::unary_function<T1, Res>
|
||||
{};
|
||||
template<typename Res, typename T1>
|
||||
struct reference_wrapper_base<Res(T1) const>
|
||||
: public sprout::unary_function<T1, Res>
|
||||
{};
|
||||
template<typename Res, typename T1>
|
||||
struct reference_wrapper_base<Res(T1) volatile>
|
||||
: public sprout::unary_function<T1, Res>
|
||||
{};
|
||||
template<typename Res, typename T1>
|
||||
struct reference_wrapper_base<Res(T1) const volatile>
|
||||
: public sprout::unary_function<T1, Res>
|
||||
{};
|
||||
template<typename Res, typename T1, typename T2>
|
||||
struct reference_wrapper_base<Res(T1, T2)>
|
||||
: public sprout::binary_function<T1, T2, Res>
|
||||
{};
|
||||
template<typename Res, typename T1, typename T2>
|
||||
struct reference_wrapper_base<Res(T1, T2) const>
|
||||
: public sprout::binary_function<T1, T2, Res>
|
||||
{};
|
||||
template<typename Res, typename T1, typename T2>
|
||||
struct reference_wrapper_base<Res(T1, T2) volatile>
|
||||
: public sprout::binary_function<T1, T2, Res>
|
||||
{};
|
||||
template<typename Res, typename T1, typename T2>
|
||||
struct reference_wrapper_base<Res(T1, T2) const volatile>
|
||||
: public sprout::binary_function<T1, T2, Res>
|
||||
{};
|
||||
template<typename Res, typename T1>
|
||||
struct reference_wrapper_base<Res(*)(T1)>
|
||||
: public sprout::unary_function<T1, Res>
|
||||
{};
|
||||
template<typename Res, typename T1, typename T2>
|
||||
struct reference_wrapper_base<Res(*)(T1, T2)>
|
||||
: public sprout::binary_function<T1, T2, Res>
|
||||
{};
|
||||
template<typename Res, typename T1>
|
||||
struct reference_wrapper_base<Res (T1::*)()>
|
||||
: public sprout::unary_function<T1*, Res>
|
||||
{};
|
||||
template<typename Res, typename T1, typename T2>
|
||||
struct reference_wrapper_base<Res (T1::*)(T2)>
|
||||
: public sprout::binary_function<T1*, T2, Res>
|
||||
{};
|
||||
template<typename Res, typename T1>
|
||||
struct reference_wrapper_base<Res (T1::*)() const>
|
||||
: public sprout::unary_function<T1 const*, Res>
|
||||
{};
|
||||
template<typename Res, typename T1, typename T2>
|
||||
struct reference_wrapper_base<Res (T1::*)(T2) const>
|
||||
: public sprout::binary_function<T1 const*, T2, Res>
|
||||
{};
|
||||
template<typename Res, typename T1>
|
||||
struct reference_wrapper_base<Res (T1::*)() volatile>
|
||||
: public sprout::unary_function<T1 volatile*, Res>
|
||||
{};
|
||||
template<typename Res, typename T1, typename T2>
|
||||
struct reference_wrapper_base<Res (T1::*)(T2) volatile>
|
||||
: public sprout::binary_function<T1 volatile*, T2, Res>
|
||||
{};
|
||||
template<typename Res, typename T1>
|
||||
struct reference_wrapper_base<Res (T1::*)() const volatile>
|
||||
: public sprout::unary_function<T1 const volatile*, Res>
|
||||
{};
|
||||
template<typename Res, typename T1, typename T2>
|
||||
struct reference_wrapper_base<Res (T1::*)(T2) const volatile>
|
||||
: public sprout::binary_function<T1 const volatile*, T2, Res>
|
||||
{};
|
||||
} // namespace detail
|
||||
|
||||
template<typename T>
|
||||
class reference_wrapper
|
||||
: public sprout::detail::reference_wrapper_base<typename std::remove_cv<T>::type>
|
||||
{
|
||||
public:
|
||||
// types
|
||||
typedef T type;
|
||||
private:
|
||||
T* t_;
|
||||
public:
|
||||
// construct/copy/destroy
|
||||
SPROUT_CONSTEXPR reference_wrapper(T& t) SPROUT_NOEXCEPT
|
||||
: t_(&t)
|
||||
{}
|
||||
reference_wrapper(T&&) = delete;
|
||||
reference_wrapper(reference_wrapper<T> const&) SPROUT_NOEXCEPT = default;
|
||||
// assignment
|
||||
reference_wrapper& operator=(reference_wrapper<T> const&) SPROUT_NOEXCEPT = default;
|
||||
// access
|
||||
SPROUT_CONSTEXPR operator T& () const SPROUT_NOEXCEPT {
|
||||
return *t_;
|
||||
}
|
||||
SPROUT_CONSTEXPR T& get() const SPROUT_NOEXCEPT {
|
||||
return *t_;
|
||||
}
|
||||
SPROUT_CONSTEXPR T* get_pointer() const SPROUT_NOEXCEPT {
|
||||
return t_;
|
||||
}
|
||||
// invocation
|
||||
template<typename... Args>
|
||||
SPROUT_CONSTEXPR typename std::result_of<T& (Args&&...)>::type
|
||||
operator() (Args&&... args) const {
|
||||
return (*t_)(sprout::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// ref
|
||||
// cref
|
||||
//
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR sprout::reference_wrapper<T> ref(T& t) SPROUT_NOEXCEPT {
|
||||
return sprout::reference_wrapper<T>(t);
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR sprout::reference_wrapper<T const> cref(T const& t) SPROUT_NOEXCEPT {
|
||||
return sprout::reference_wrapper<T const>(t);
|
||||
}
|
||||
template<typename T>
|
||||
void ref(T const&&) = delete;
|
||||
template<typename T>
|
||||
void cref(T const&&) = delete;
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR sprout::reference_wrapper<T> ref(sprout::reference_wrapper<T> t) SPROUT_NOEXCEPT {
|
||||
return t;
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR sprout::reference_wrapper<T const> cref(sprout::reference_wrapper<T> t) SPROUT_NOEXCEPT {
|
||||
return sprout::reference_wrapper<T const>(t.get());
|
||||
}
|
||||
|
||||
//
|
||||
// is_reference_wrapper
|
||||
//
|
||||
template<typename T>
|
||||
struct is_reference_wrapper
|
||||
: public std::false_type
|
||||
{};
|
||||
template<typename T>
|
||||
struct is_reference_wrapper<sprout::reference_wrapper<T> >
|
||||
: public std::true_type
|
||||
{};
|
||||
template<typename T>
|
||||
struct is_reference_wrapper<T const>
|
||||
: public sprout::is_reference_wrapper<T>
|
||||
{};
|
||||
template<typename T>
|
||||
struct is_reference_wrapper<T volatile>
|
||||
: public sprout::is_reference_wrapper<T>
|
||||
{};
|
||||
template<typename T>
|
||||
struct is_reference_wrapper<T const volatile>
|
||||
: public sprout::is_reference_wrapper<T>
|
||||
{};
|
||||
|
||||
//
|
||||
// unwrap_reference
|
||||
//
|
||||
template<typename T>
|
||||
struct unwrap_reference {
|
||||
public:
|
||||
typedef T type;
|
||||
};
|
||||
template<typename T>
|
||||
struct unwrap_reference<sprout::reference_wrapper<T> > {
|
||||
public:
|
||||
typedef T type;
|
||||
};
|
||||
template<typename T>
|
||||
struct unwrap_reference<T const>
|
||||
: public sprout::unwrap_reference<T>
|
||||
{};
|
||||
template<typename T>
|
||||
struct unwrap_reference<T volatile>
|
||||
: public sprout::unwrap_reference<T>
|
||||
{};
|
||||
template<typename T>
|
||||
struct unwrap_reference<T const volatile>
|
||||
: public sprout::unwrap_reference<T>
|
||||
{};
|
||||
|
||||
//
|
||||
// unwrap_ref
|
||||
//
|
||||
template<typename T>
|
||||
inline typename sprout::unwrap_reference<T>::type& unwrap_ref(T& t) {
|
||||
return t;
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR typename sprout::unwrap_reference<T const>::type& unwrap_ref(T const& t) {
|
||||
return t;
|
||||
}
|
||||
|
||||
//
|
||||
// get_pointer
|
||||
//
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR T* get_pointer(sprout::reference_wrapper<T> const& r) {
|
||||
return r.get_pointer();
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_REF_HPP
|
18
sprout/functional/unary_function.hpp
Normal file
18
sprout/functional/unary_function.hpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_UNARY_FUNCTION_HPP
|
||||
#define SPROUT_FUNCTIONAL_UNARY_FUNCTION_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// unary_function
|
||||
//
|
||||
template<typename Arg, typename Result>
|
||||
struct unary_function {
|
||||
public:
|
||||
typedef Arg argument_type;
|
||||
typedef Result result_type;
|
||||
};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_UNARY_FUNCTION_HPP
|
100
sprout/functional/weak_result_type.hpp
Normal file
100
sprout/functional/weak_result_type.hpp
Normal file
|
@ -0,0 +1,100 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_WEAK_RESULT_TYPE_HPP
|
||||
#define SPROUT_FUNCTIONAL_WEAK_RESULT_TYPE_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 {
|
||||
namespace detail {
|
||||
//
|
||||
// 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);
|
||||
|
||||
//
|
||||
// inherit_if_result_type
|
||||
// inherit_if_argument_type
|
||||
// inherit_if_first_argument_type
|
||||
// inherit_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);
|
||||
|
||||
template<typename F>
|
||||
struct weak_result_type_impl
|
||||
: public sprout::detail::inherit_if_result_type<F>
|
||||
{};
|
||||
template<typename F>
|
||||
struct weak_result_type_impl<F const>
|
||||
: public sprout::detail::weak_result_type_impl<F>
|
||||
{};
|
||||
template<typename F>
|
||||
struct weak_result_type_impl<F volatile>
|
||||
: public sprout::detail::weak_result_type_impl<F>
|
||||
{};
|
||||
template<typename F>
|
||||
struct weak_result_type_impl<F const volatile>
|
||||
: public sprout::detail::weak_result_type_impl<F>
|
||||
{};
|
||||
template<typename R, typename... Args>
|
||||
struct weak_result_type_impl<R (Args...)> {
|
||||
public:
|
||||
typedef R result_type;
|
||||
};
|
||||
template<typename R, typename... Args>
|
||||
struct weak_result_type_impl<R (Args......)> {
|
||||
public:
|
||||
typedef R result_type;
|
||||
};
|
||||
template<typename R, typename... Args>
|
||||
struct weak_result_type_impl<R (&)(Args...)> {
|
||||
public:
|
||||
typedef R result_type;
|
||||
};
|
||||
template<typename R, typename... Args>
|
||||
struct weak_result_type_impl<R (&)(Args......)> {
|
||||
public:
|
||||
typedef R result_type;
|
||||
};
|
||||
template<typename R, typename... Args>
|
||||
struct weak_result_type_impl<R (*)(Args...)> {
|
||||
public:
|
||||
typedef R result_type;
|
||||
};
|
||||
template<typename R, typename... Args>
|
||||
struct weak_result_type_impl<R (*)(Args......)> {
|
||||
public:
|
||||
typedef R result_type;
|
||||
};
|
||||
template<typename R, typename Class, typename... Args>
|
||||
struct weak_result_type_impl<R (Class::*)(Args...)> {
|
||||
public:
|
||||
typedef R result_type;
|
||||
};
|
||||
template<typename R, typename Class, typename... Args>
|
||||
struct weak_result_type_impl<R (Class::*)(Args......)> {
|
||||
public:
|
||||
typedef R result_type;
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// weak_result_type
|
||||
//
|
||||
template<typename F>
|
||||
struct weak_result_type
|
||||
: public sprout::detail::weak_result_type_impl<typename std::remove_cv<F>::type>
|
||||
{};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_WEAK_RESULT_TYPE_HPP
|
|
@ -215,14 +215,9 @@ namespace sprout {
|
|||
: inherited_type(elements...)
|
||||
{}
|
||||
template<typename... UTypes>
|
||||
SPROUT_CONSTEXPR explicit tuple(UTypes const&... elements)
|
||||
: inherited_type(elements...)
|
||||
SPROUT_CONSTEXPR explicit tuple(UTypes&&... elements)
|
||||
: inherited_type(sprout::forward<UTypes>(elements)...)
|
||||
{}
|
||||
// !!!
|
||||
// template<typename... UTypes>
|
||||
// SPROUT_CONSTEXPR explicit tuple(UTypes&&... elements)
|
||||
// : inherited_type(sprout::forward<UTypes>(elements)...)
|
||||
// {}
|
||||
SPROUT_CONSTEXPR tuple(tuple const&) = default;
|
||||
SPROUT_CONSTEXPR tuple(tuple&&) = default;
|
||||
template<typename... UTypes>
|
||||
|
|
|
@ -4,5 +4,7 @@
|
|||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/lvalue_reference.hpp>
|
||||
#include <sprout/type_traits/const_reference.hpp>
|
||||
#include <sprout/type_traits/has_xxx.hpp>
|
||||
#include <sprout/type_traits/inherit_if_xxx.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_TYPE_TRAITS_HPP
|
||||
|
|
27
sprout/type_traits/has_xxx.hpp
Normal file
27
sprout/type_traits/has_xxx.hpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
#ifndef SPROUT_TYPE_TRAITS_HAS_XXX_HPP
|
||||
#define SPROUT_TYPE_TRAITS_HAS_XXX_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/preprocessor/cat.hpp>
|
||||
|
||||
//
|
||||
// SPROUT_HAS_XXX_TYPE_DEF
|
||||
//
|
||||
#define SPROUT_HAS_XXX_TYPE_DEF(NAME, TYPE) \
|
||||
template<typename T, typename Enable = typename T::TYPE> \
|
||||
std::true_type SPROUT_PP_CAT(SPROUT_PP_CAT(sprout_has_xxx_impl_check_type_, TYPE), __LINE__)(int); \
|
||||
template<typename T> \
|
||||
std::false_type SPROUT_PP_CAT(SPROUT_PP_CAT(sprout_has_xxx_impl_check_type_, TYPE), __LINE__)(long); \
|
||||
template<typename T> \
|
||||
struct NAME \
|
||||
: decltype(SPROUT_PP_CAT(SPROUT_PP_CAT(sprout_has_xxx_impl_check_type_, TYPE), __LINE__)<T>( 0 ) ) \
|
||||
{}
|
||||
|
||||
//
|
||||
// SPROUT_HAS_XXX_TYPE_DEF_LAZY
|
||||
//
|
||||
#define SPROUT_HAS_XXX_TYPE_DEF_LAZY(TYPE) \
|
||||
SPROUT_HAS_XXX_TYPE_DEF(SPROUT_PP_CAT(has_, TYPE), TYPE)
|
||||
|
||||
#endif // #ifndef SPROUT_TYPE_TRAITS_HAS_XXX_HPP
|
31
sprout/type_traits/inherit_if_xxx.hpp
Normal file
31
sprout/type_traits/inherit_if_xxx.hpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
#ifndef SPROUT_TYPE_TRAITS_INHERIT_IF_XXX_HPP
|
||||
#define SPROUT_TYPE_TRAITS_INHERIT_IF_XXX_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/preprocessor/cat.hpp>
|
||||
#include <sprout/type_traits/has_xxx.hpp>
|
||||
|
||||
//
|
||||
// SPROUT_INHERIT_IF_XXX_TYPE_DEF
|
||||
//
|
||||
#define SPROUT_INHERIT_IF_XXX_TYPE_DEF(NAME, TYPE) \
|
||||
SPROUT_HAS_XXX_TYPE_DEF(SPROUT_PP_CAT(SPROUT_PP_CAT(sprout_inherit_if_xxx_type_def_impl_has_, TYPE), __LINE__), TYPE); \
|
||||
template<typename T, typename Enable = void> \
|
||||
struct NAME {}; \
|
||||
template<typename T> \
|
||||
struct NAME< \
|
||||
T, \
|
||||
typename std::enable_if<SPROUT_PP_CAT(SPROUT_PP_CAT(sprout_inherit_if_xxx_type_def_impl_has_, TYPE), __LINE__)<T>::value>::type \
|
||||
> { \
|
||||
public: \
|
||||
typedef typename T::TYPE TYPE; \
|
||||
}
|
||||
|
||||
//
|
||||
// SPROUT_INHERIT_IF_XXX_TYPE_DEF_LAZY
|
||||
//
|
||||
#define SPROUT_INHERIT_IF_XXX_TYPE_DEF_LAZY(TYPE) \
|
||||
SPROUT_INHERIT_IF_XXX_TYPE_DEF(SPROUT_PP_CAT(inherit_if_, TYPE), TYPE)
|
||||
|
||||
#endif // #ifndef SPROUT_TYPE_TRAITS_INHERIT_IF_XXX_HPP
|
Loading…
Reference in a new issue