1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00

fix variadic-or-positional placeholders type

This commit is contained in:
bolero-MURAKAMI 2013-07-10 12:15:11 +09:00
parent d435c59657
commit 95d8db9289
7 changed files with 195 additions and 108 deletions

View file

@ -14,6 +14,7 @@
#include <sprout/tuple/tuple/get.hpp> #include <sprout/tuple/tuple/get.hpp>
#include <sprout/tuple/tuple/make_tuple.hpp> #include <sprout/tuple/tuple/make_tuple.hpp>
#include <sprout/type/algorithm/find_index_if.hpp> #include <sprout/type/algorithm/find_index_if.hpp>
#include <sprout/type/algorithm/lower_bound_index.hpp>
#include <sprout/type/integral_array.hpp> #include <sprout/type/integral_array.hpp>
#include <sprout/functional/ref.hpp> #include <sprout/functional/ref.hpp>
#include <sprout/functional/mem_fn.hpp> #include <sprout/functional/mem_fn.hpp>
@ -188,21 +189,14 @@ namespace sprout {
return sprout::tuples::get<I>(const_cast<sprout::tuples::tuple<Types...> const&>(tuple)); return sprout::tuples::get<I>(const_cast<sprout::tuples::tuple<Types...> const&>(tuple));
} }
template<typename T, typename = void>
struct is_variadic_placeholder
: public std::integral_constant<
bool,
(sprout::is_placeholder<T>::value
<= sprout::is_placeholder<decltype(sprout::placeholders::_va)>::value
)
>
{};
struct is_variadic_placeholder_pred { struct is_variadic_placeholder_pred {
public: public:
template<typename T> template<typename T>
struct apply struct apply
: public sprout::detail::is_variadic_placeholder<T> : public std::integral_constant<
bool,
(sprout::is_variadic_placeholder<T>::value > 0)
>
{}; {};
}; };
template<typename Bounds, typename = void> template<typename Bounds, typename = void>
@ -213,21 +207,9 @@ namespace sprout {
> >
{}; {};
template<typename T, typename = void>
struct tail_place
: public std::integral_constant<int, -1>
{};
template<typename T> template<typename T>
struct tail_place< struct tail_place
T, : public std::integral_constant<int, sprout::is_variadic_placeholder<T>::value - 1>
typename std::enable_if<sprout::detail::is_variadic_placeholder<T>::value>::type
>
: public std::integral_constant<
int,
(sprout::is_placeholder<decltype(sprout::placeholders::_va)>::value
- sprout::is_placeholder<T>::value
)
>
{}; {};
template<typename T, std::size_t ArgSize, typename = void> template<typename T, std::size_t ArgSize, typename = void>
@ -237,7 +219,7 @@ namespace sprout {
template<typename T, std::size_t ArgSize> template<typename T, std::size_t ArgSize>
struct bound_size< struct bound_size<
T, ArgSize, T, ArgSize,
typename std::enable_if<sprout::detail::is_variadic_placeholder<T>::value>::type typename std::enable_if<(sprout::is_variadic_placeholder<T>::value > 0)>::type
> >
: public std::integral_constant< : public std::integral_constant<
std::size_t, std::size_t,
@ -292,39 +274,11 @@ namespace sprout {
: public sprout::make_index_tuple<sprout::detail::bounds_size<Bounds, ArgSize>::value> : public sprout::make_index_tuple<sprout::detail::bounds_size<Bounds, ArgSize>::value>
{}; {};
struct meta_less_ {
public:
template<typename T, typename U>
struct apply
: public std::integral_constant<bool, ((T::value) < (U::value))>
{};
};
template<std::size_t I, typename Tuple, typename T, typename Compare, typename = void>
struct lower_bound_index_impl
: public std::integral_constant<std::size_t, I>
{};
template<std::size_t I, typename Tuple, typename T, typename Compare>
struct lower_bound_index_impl<
I, Tuple, T, Compare,
typename std::enable_if<(I < sprout::tuples::tuple_size<Tuple>::value)>::type
>
: public std::conditional<
Compare::template apply<typename sprout::tuples::tuple_element<I, Tuple>::type, T>::type::value,
sprout::detail::lower_bound_index_impl<I + 1, Tuple, T, Compare>,
std::integral_constant<std::size_t, I>
>::type
{};
template<typename Tuple, typename T, typename Compare = sprout::detail::meta_less_>
struct lower_bound_index
: public sprout::detail::lower_bound_index_impl<0, Tuple, T, Compare>
{};
template<sprout::index_t I, typename Bounds, std::size_t ArgSize> template<sprout::index_t I, typename Bounds, std::size_t ArgSize>
struct bound_position struct bound_position
: public std::integral_constant< : public std::integral_constant<
sprout::index_t, sprout::index_t,
(sprout::detail::lower_bound_index< (sprout::types::lower_bound_index<
typename sprout::detail::bounds_partial_size<Bounds, ArgSize>::type, typename sprout::detail::bounds_partial_size<Bounds, ArgSize>::type,
std::integral_constant<std::size_t, I + 1> std::integral_constant<std::size_t, I + 1>
>::type::value - 1 >::type::value - 1
@ -334,11 +288,15 @@ namespace sprout {
template<sprout::index_t I, typename Bounds, std::size_t ArgSize> template<sprout::index_t I, typename Bounds, std::size_t ArgSize>
struct is_variadic_part struct is_variadic_part
: public sprout::detail::is_variadic_placeholder< : public std::integral_constant<
bool,
(sprout::is_variadic_placeholder<
typename sprout::tuples::tuple_element< typename sprout::tuples::tuple_element<
sprout::detail::bound_position<I, Bounds, ArgSize>::value, sprout::detail::bound_position<I, Bounds, ArgSize>::value,
Bounds Bounds
>::type >::type
>::value > 0
)
> >
{}; {};
@ -730,7 +688,7 @@ namespace sprout {
template<sprout::index_t Index, typename BoundArg> template<sprout::index_t Index, typename BoundArg>
struct complete_placeholder< struct complete_placeholder<
Index, BoundArg, Index, BoundArg,
typename std::enable_if<!(sprout::is_placeholder<BoundArg>::value == sprout::is_placeholder<decltype(sprout::placeholders::_)>::value)>::type typename std::enable_if<!sprout::is_positional_placeholder<BoundArg>::value>::type
> { > {
public: public:
typedef BoundArg type; typedef BoundArg type;
@ -738,7 +696,7 @@ namespace sprout {
template<sprout::index_t Index, typename BoundArg> template<sprout::index_t Index, typename BoundArg>
struct complete_placeholder< struct complete_placeholder<
Index, BoundArg, Index, BoundArg,
typename std::enable_if<(sprout::is_placeholder<BoundArg>::value == sprout::is_placeholder<decltype(sprout::placeholders::_)>::value)>::type typename std::enable_if<sprout::is_positional_placeholder<BoundArg>::value>::type
> { > {
public: public:
typedef sprout::placeholder<Index + 1> type; typedef sprout::placeholder<Index + 1> type;

View file

@ -9,19 +9,22 @@ namespace sprout {
// placeholder // placeholder
// //
template<int N> template<int N>
struct placeholder struct placeholder {};
// : public std::integral_constant<int, N> //
{}; // positional_placeholder
template<> //
struct placeholder<-1> struct positional_placeholder {
// : public std::integral_constant<int, -1>
{
public: public:
template<int N2> template<int N>
SPROUT_CONSTEXPR operator sprout::placeholder<N2>() const { SPROUT_CONSTEXPR operator sprout::placeholder<N>() const {
return sprout::placeholder<N2>(); return sprout::placeholder<N>();
} }
}; };
//
// variadic_placeholder
//
template<int N>
struct variadic_placeholder {};
namespace placeholders { namespace placeholders {
namespace { namespace {
@ -56,39 +59,39 @@ namespace sprout {
SPROUT_STATIC_CONSTEXPR sprout::placeholder<29> _29 = {}; SPROUT_STATIC_CONSTEXPR sprout::placeholder<29> _29 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<30> _30 = {}; SPROUT_STATIC_CONSTEXPR sprout::placeholder<30> _30 = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-1> _ = {}; SPROUT_STATIC_CONSTEXPR sprout::positional_placeholder _ = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256> _va = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<0> _va = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 1> _1tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<1> _1tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 2> _2tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<2> _2tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 3> _3tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<3> _3tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 4> _4tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<4> _4tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 5> _5tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<5> _5tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 6> _6tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<6> _6tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 7> _7tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<7> _7tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 8> _8tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<8> _8tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 9> _9tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<9> _9tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 10> _10tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<10> _10tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 11> _11tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<11> _11tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 12> _12tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<12> _12tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 13> _13tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<13> _13tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 14> _14tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<14> _14tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 15> _15tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<15> _15tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 16> _16tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<16> _16tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 17> _17tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<17> _17tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 18> _18tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<18> _18tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 19> _19tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<19> _19tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 20> _20tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<20> _20tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 21> _21tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<21> _21tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 22> _22tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<22> _22tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 23> _23tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<23> _23tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 24> _24tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<24> _24tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 25> _25tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<25> _25tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 26> _26tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<26> _26tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 27> _27tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<27> _27tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 28> _28tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<28> _28tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 29> _29tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<29> _29tail = {};
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 30> _30tail = {}; SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<30> _30tail = {};
} // anonymous-namespace } // anonymous-namespace
} // namespace placeholders } // namespace placeholders
using sprout::placeholders::_1; using sprout::placeholders::_1;
@ -163,10 +166,6 @@ namespace sprout {
struct is_placeholder struct is_placeholder
: public std::integral_constant<int, 0> : public std::integral_constant<int, 0>
{}; {};
template<int N>
struct is_placeholder<sprout::placeholder<N> >
: public std::integral_constant<int, N>
{};
template<typename T> template<typename T>
struct is_placeholder<T const> struct is_placeholder<T const>
: public sprout::is_placeholder<T> : public sprout::is_placeholder<T>
@ -179,6 +178,58 @@ namespace sprout {
struct is_placeholder<T const volatile> struct is_placeholder<T const volatile>
: public sprout::is_placeholder<T> : public sprout::is_placeholder<T>
{}; {};
template<int N>
struct is_placeholder<sprout::placeholder<N> >
: public std::integral_constant<int, N>
{};
//
// is_positional_placeholder
//
template<typename T>
struct is_positional_placeholder
: public std::integral_constant<int, 0>
{};
template<typename T>
struct is_positional_placeholder<T const>
: public sprout::is_positional_placeholder<T>
{};
template<typename T>
struct is_positional_placeholder<T volatile>
: public sprout::is_positional_placeholder<T>
{};
template<typename T>
struct is_positional_placeholder<T const volatile>
: public sprout::is_positional_placeholder<T>
{};
template<>
struct is_positional_placeholder<sprout::positional_placeholder>
: public std::integral_constant<int, 1>
{};
//
// is_variadic_placeholder
//
template<typename T>
struct is_variadic_placeholder
: public std::integral_constant<int, 0>
{};
template<typename T>
struct is_variadic_placeholder<T const>
: public sprout::is_variadic_placeholder<T>
{};
template<typename T>
struct is_variadic_placeholder<T volatile>
: public sprout::is_variadic_placeholder<T>
{};
template<typename T>
struct is_variadic_placeholder<T const volatile>
: public sprout::is_variadic_placeholder<T>
{};
template<int N>
struct is_variadic_placeholder<sprout::variadic_placeholder<N> >
: public std::integral_constant<int, N + 1>
{};
} // namespace sprout } // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_BIND_PLACEHOLDER_HPP #endif // #ifndef SPROUT_FUNCTIONAL_BIND_PLACEHOLDER_HPP

View file

@ -7,6 +7,7 @@
#include <sprout/type/integral_array.hpp> #include <sprout/type/integral_array.hpp>
#include <sprout/type/string.hpp> #include <sprout/type/string.hpp>
#include <sprout/type/rebind_types.hpp> #include <sprout/type/rebind_types.hpp>
#include <sprout/type/functional.hpp>
#include <sprout/type/algorithm.hpp> #include <sprout/type/algorithm.hpp>
#include <sprout/type/operation.hpp> #include <sprout/type/operation.hpp>

View file

@ -4,5 +4,6 @@
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/type/algorithm/find_index.hpp> #include <sprout/type/algorithm/find_index.hpp>
#include <sprout/type/algorithm/find_index_if.hpp> #include <sprout/type/algorithm/find_index_if.hpp>
#include <sprout/type/algorithm/lower_bound_index.hpp>
#endif // #ifndef SPROUT_TYPE_ALGORITHM_HPP #endif // #ifndef SPROUT_TYPE_ALGORITHM_HPP

View file

@ -0,0 +1,39 @@
#ifndef SPROUT_TYPE_ALGORITHM_LOWER_BOUND_INDEX_HPP
#define SPROUT_TYPE_ALGORITHM_LOWER_BOUND_INDEX_HPP
#include <cstddef>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/type/functional/less.hpp>
#include <sprout/type/tuple.hpp>
namespace sprout {
namespace types {
namespace detail {
template<std::size_t I, typename Tuple, typename T, typename Compare, typename = void>
struct lower_bound_index_impl
: public std::integral_constant<std::size_t, I>
{};
template<std::size_t I, typename Tuple, typename T, typename Compare>
struct lower_bound_index_impl<
I, Tuple, T, Compare,
typename std::enable_if<(I < sprout::tuples::tuple_size<Tuple>::value)>::type
>
: public std::conditional<
Compare::template apply<typename sprout::tuples::tuple_element<I, Tuple>::type, T>::type::value,
sprout::types::detail::lower_bound_index_impl<I + 1, Tuple, T, Compare>,
std::integral_constant<std::size_t, I>
>::type
{};
} // namespace detail
//
// lower_bound_index
//
template<typename Tuple, typename T, typename Compare = sprout::types::less_>
struct lower_bound_index
: public sprout::types::detail::lower_bound_index_impl<0, Tuple, T, Compare>
{};
} // namespace types
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_ALGORITHM_LOWER_BOUND_INDEX_HPP

View file

@ -0,0 +1,7 @@
#ifndef SPROUT_TYPE_FUNCTIONAL_HPP
#define SPROUT_TYPE_FUNCTIONAL_HPP
#include <sprout/config.hpp>
#include <sprout/type/functional/less.hpp>
#endif // #ifndef SPROUT_TYPE_FUNCTIONAL_HPP

View file

@ -0,0 +1,30 @@
#ifndef SPROUT_TYPE_FUNCTIONAL_LESS_HPP
#define SPROUT_TYPE_FUNCTIONAL_LESS_HPP
#include <type_traits>
#include <sprout/config.hpp>
namespace sprout {
namespace types {
//
// less
//
template<typename T, typename U>
struct less
: public std::integral_constant<bool, ((T::value) < (U::value))>
{};
//
// less_
//
struct less_ {
public:
template<typename T, typename U>
struct apply
: public sprout::types::less<T, U>
{};
};
} // namespace types
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_FUNCTIONAL_LESS_HPP