mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-11-14 10:39:05 +00:00
fix variadic-or-positional placeholders type
This commit is contained in:
parent
d435c59657
commit
95d8db9289
7 changed files with 195 additions and 108 deletions
|
@ -14,6 +14,7 @@
|
|||
#include <sprout/tuple/tuple/get.hpp>
|
||||
#include <sprout/tuple/tuple/make_tuple.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/functional/ref.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));
|
||||
}
|
||||
|
||||
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 {
|
||||
public:
|
||||
template<typename T>
|
||||
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>
|
||||
|
@ -213,21 +207,9 @@ namespace sprout {
|
|||
>
|
||||
{};
|
||||
|
||||
template<typename T, typename = void>
|
||||
struct tail_place
|
||||
: public std::integral_constant<int, -1>
|
||||
{};
|
||||
template<typename T>
|
||||
struct tail_place<
|
||||
T,
|
||||
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
|
||||
)
|
||||
>
|
||||
struct tail_place
|
||||
: public std::integral_constant<int, sprout::is_variadic_placeholder<T>::value - 1>
|
||||
{};
|
||||
|
||||
template<typename T, std::size_t ArgSize, typename = void>
|
||||
|
@ -237,7 +219,7 @@ namespace sprout {
|
|||
template<typename T, std::size_t ArgSize>
|
||||
struct bound_size<
|
||||
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<
|
||||
std::size_t,
|
||||
|
@ -292,39 +274,11 @@ namespace sprout {
|
|||
: 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>
|
||||
struct bound_position
|
||||
: public std::integral_constant<
|
||||
sprout::index_t,
|
||||
(sprout::detail::lower_bound_index<
|
||||
(sprout::types::lower_bound_index<
|
||||
typename sprout::detail::bounds_partial_size<Bounds, ArgSize>::type,
|
||||
std::integral_constant<std::size_t, I + 1>
|
||||
>::type::value - 1
|
||||
|
@ -334,11 +288,15 @@ namespace sprout {
|
|||
|
||||
template<sprout::index_t I, typename Bounds, std::size_t ArgSize>
|
||||
struct is_variadic_part
|
||||
: public sprout::detail::is_variadic_placeholder<
|
||||
typename sprout::tuples::tuple_element<
|
||||
sprout::detail::bound_position<I, Bounds, ArgSize>::value,
|
||||
Bounds
|
||||
>::type
|
||||
: public std::integral_constant<
|
||||
bool,
|
||||
(sprout::is_variadic_placeholder<
|
||||
typename sprout::tuples::tuple_element<
|
||||
sprout::detail::bound_position<I, Bounds, ArgSize>::value,
|
||||
Bounds
|
||||
>::type
|
||||
>::value > 0
|
||||
)
|
||||
>
|
||||
{};
|
||||
|
||||
|
@ -730,7 +688,7 @@ namespace sprout {
|
|||
template<sprout::index_t Index, typename BoundArg>
|
||||
struct complete_placeholder<
|
||||
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:
|
||||
typedef BoundArg type;
|
||||
|
@ -738,7 +696,7 @@ namespace sprout {
|
|||
template<sprout::index_t Index, typename BoundArg>
|
||||
struct complete_placeholder<
|
||||
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:
|
||||
typedef sprout::placeholder<Index + 1> type;
|
||||
|
|
|
@ -9,19 +9,22 @@ namespace sprout {
|
|||
// placeholder
|
||||
//
|
||||
template<int N>
|
||||
struct placeholder
|
||||
// : public std::integral_constant<int, N>
|
||||
{};
|
||||
template<>
|
||||
struct placeholder<-1>
|
||||
// : public std::integral_constant<int, -1>
|
||||
{
|
||||
struct placeholder {};
|
||||
//
|
||||
// positional_placeholder
|
||||
//
|
||||
struct positional_placeholder {
|
||||
public:
|
||||
template<int N2>
|
||||
SPROUT_CONSTEXPR operator sprout::placeholder<N2>() const {
|
||||
return sprout::placeholder<N2>();
|
||||
template<int N>
|
||||
SPROUT_CONSTEXPR operator sprout::placeholder<N>() const {
|
||||
return sprout::placeholder<N>();
|
||||
}
|
||||
};
|
||||
//
|
||||
// variadic_placeholder
|
||||
//
|
||||
template<int N>
|
||||
struct variadic_placeholder {};
|
||||
|
||||
namespace placeholders {
|
||||
namespace {
|
||||
|
@ -56,39 +59,39 @@ namespace sprout {
|
|||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<29> _29 = {};
|
||||
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::placeholder<-256 - 1> _1tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 2> _2tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 3> _3tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 4> _4tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 5> _5tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 6> _6tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 7> _7tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 8> _8tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 9> _9tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 10> _10tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 11> _11tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 12> _12tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 13> _13tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 14> _14tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 15> _15tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 16> _16tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 17> _17tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 18> _18tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 19> _19tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 20> _20tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 21> _21tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 22> _22tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 23> _23tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 24> _24tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 25> _25tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 26> _26tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 27> _27tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 28> _28tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 29> _29tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::placeholder<-256 - 30> _30tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<0> _va = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<1> _1tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<2> _2tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<3> _3tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<4> _4tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<5> _5tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<6> _6tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<7> _7tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<8> _8tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<9> _9tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<10> _10tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<11> _11tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<12> _12tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<13> _13tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<14> _14tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<15> _15tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<16> _16tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<17> _17tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<18> _18tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<19> _19tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<20> _20tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<21> _21tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<22> _22tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<23> _23tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<24> _24tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<25> _25tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<26> _26tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<27> _27tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<28> _28tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<29> _29tail = {};
|
||||
SPROUT_STATIC_CONSTEXPR sprout::variadic_placeholder<30> _30tail = {};
|
||||
} // anonymous-namespace
|
||||
} // namespace placeholders
|
||||
using sprout::placeholders::_1;
|
||||
|
@ -163,10 +166,6 @@ namespace sprout {
|
|||
struct is_placeholder
|
||||
: public std::integral_constant<int, 0>
|
||||
{};
|
||||
template<int N>
|
||||
struct is_placeholder<sprout::placeholder<N> >
|
||||
: public std::integral_constant<int, N>
|
||||
{};
|
||||
template<typename T>
|
||||
struct is_placeholder<T const>
|
||||
: public sprout::is_placeholder<T>
|
||||
|
@ -179,6 +178,58 @@ namespace sprout {
|
|||
struct is_placeholder<T const volatile>
|
||||
: 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
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_BIND_PLACEHOLDER_HPP
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <sprout/type/integral_array.hpp>
|
||||
#include <sprout/type/string.hpp>
|
||||
#include <sprout/type/rebind_types.hpp>
|
||||
#include <sprout/type/functional.hpp>
|
||||
#include <sprout/type/algorithm.hpp>
|
||||
#include <sprout/type/operation.hpp>
|
||||
|
||||
|
|
|
@ -4,5 +4,6 @@
|
|||
#include <sprout/config.hpp>
|
||||
#include <sprout/type/algorithm/find_index.hpp>
|
||||
#include <sprout/type/algorithm/find_index_if.hpp>
|
||||
#include <sprout/type/algorithm/lower_bound_index.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_TYPE_ALGORITHM_HPP
|
||||
|
|
39
sprout/type/algorithm/lower_bound_index.hpp
Normal file
39
sprout/type/algorithm/lower_bound_index.hpp
Normal 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
|
7
sprout/type/functional.hpp
Normal file
7
sprout/type/functional.hpp
Normal 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
|
30
sprout/type/functional/less.hpp
Normal file
30
sprout/type/functional/less.hpp
Normal 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
|
Loading…
Reference in a new issue