mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
sprout/utility/enabler_if.hpp 追加
This commit is contained in:
parent
e11da4400b
commit
86073fea83
3 changed files with 31 additions and 23 deletions
|
@ -1,10 +0,0 @@
|
||||||
#ifndef SPROUT_UTILITY_ENABLER_HPP
|
|
||||||
#define SPROUT_UTILITY_ENABLER_HPP
|
|
||||||
|
|
||||||
#include <sprout/config.hpp>
|
|
||||||
|
|
||||||
namespace sprout {
|
|
||||||
extern void* enabler;
|
|
||||||
} // namespace sprout
|
|
||||||
|
|
||||||
#endif // #ifndef SPROUT_UTILITY_ENABLER_HPP
|
|
23
sprout/utility/enabler_if.hpp
Normal file
23
sprout/utility/enabler_if.hpp
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#ifndef SPROUT_UTILITY_ENABLER_IF_HPP
|
||||||
|
#define SPROUT_UTILITY_ENABLER_IF_HPP
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
|
||||||
|
namespace sprout {
|
||||||
|
//
|
||||||
|
// enabler_t
|
||||||
|
// enabler
|
||||||
|
//
|
||||||
|
typedef void* enabler_t;
|
||||||
|
extern enabler_t enabler;
|
||||||
|
//
|
||||||
|
// enabler_if
|
||||||
|
//
|
||||||
|
template<bool C>
|
||||||
|
class enabler_if
|
||||||
|
: public std::enable_if<C, enabler_t&>
|
||||||
|
{};
|
||||||
|
} // namespace sprout
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_UTILITY_ENABLER_IF_HPP
|
|
@ -5,7 +5,7 @@
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <sprout/config.hpp>
|
#include <sprout/config.hpp>
|
||||||
#include <sprout/utility/forward.hpp>
|
#include <sprout/utility/forward.hpp>
|
||||||
#include <sprout/utility/enabler.hpp>
|
#include <sprout/utility/enabler_if.hpp>
|
||||||
|
|
||||||
namespace sprout {
|
namespace sprout {
|
||||||
//
|
//
|
||||||
|
@ -15,7 +15,7 @@ namespace sprout {
|
||||||
template<std::size_t N, typename Head, typename... Tail>
|
template<std::size_t N, typename Head, typename... Tail>
|
||||||
struct tppack_at_impl_1 {
|
struct tppack_at_impl_1 {
|
||||||
public:
|
public:
|
||||||
typedef typename sprout::detail::tppack_at_impl<N - 1, Tail...>::type type;
|
typedef typename sprout::detail::tppack_at_impl_1<N - 1, Tail...>::type type;
|
||||||
};
|
};
|
||||||
template<typename Head, typename... Tail>
|
template<typename Head, typename... Tail>
|
||||||
struct tppack_at_impl_1<0, Head, Tail...> {
|
struct tppack_at_impl_1<0, Head, Tail...> {
|
||||||
|
@ -24,18 +24,13 @@ namespace sprout {
|
||||||
};
|
};
|
||||||
template<
|
template<
|
||||||
std::size_t N,
|
std::size_t N,
|
||||||
typename... Args,
|
typename... Args
|
||||||
typename std::enable_if<(N < sizeof...(Args))>::type*& = sprout::enabler
|
|
||||||
>
|
>
|
||||||
struct tppack_at_impl
|
struct tppack_at_impl
|
||||||
: public sprout::detail::tppack_at_impl_1<N, Args...>
|
: public sprout::detail::tppack_at_impl_1<N, Args...>
|
||||||
{};
|
{
|
||||||
template<
|
static_assert(N < sizeof...(Args), "N < sizeof...(Args)");
|
||||||
std::size_t N,
|
};
|
||||||
typename... Args,
|
|
||||||
typename std::enable_if<(N >= sizeof...(Args))>::type*& = sprout::enabler
|
|
||||||
>
|
|
||||||
struct tppack_at_impl {};
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
template<std::size_t N, typename... Args>
|
template<std::size_t N, typename... Args>
|
||||||
struct tppack_at
|
struct tppack_at
|
||||||
|
@ -51,7 +46,7 @@ namespace sprout {
|
||||||
typename R,
|
typename R,
|
||||||
typename Head,
|
typename Head,
|
||||||
typename... Tail,
|
typename... Tail,
|
||||||
typename std::enable_if<N == 0>::type*& = sprout::enabler
|
typename sprout::enabler_if<N == 0>::type = sprout::enabler
|
||||||
>
|
>
|
||||||
SPROUT_CONSTEXPR R fppack_at_impl(Head&& head, Tail&&... tail) {
|
SPROUT_CONSTEXPR R fppack_at_impl(Head&& head, Tail&&... tail) {
|
||||||
return sprout::forward<Head>(head);
|
return sprout::forward<Head>(head);
|
||||||
|
@ -61,7 +56,7 @@ namespace sprout {
|
||||||
typename R,
|
typename R,
|
||||||
typename Head,
|
typename Head,
|
||||||
typename... Tail,
|
typename... Tail,
|
||||||
typename std::enable_if<N != 0>::type*& = sprout::enabler
|
typename sprout::enabler_if<N != 0>::type = sprout::enabler
|
||||||
>
|
>
|
||||||
SPROUT_CONSTEXPR R fppack_at_impl(Head&& head, Tail&&... tail) {
|
SPROUT_CONSTEXPR R fppack_at_impl(Head&& head, Tail&&... tail) {
|
||||||
return sprout::detail::fppack_at_impl<N - 1, R>(sprout::forward<Tail>(tail)...);
|
return sprout::detail::fppack_at_impl<N - 1, R>(sprout::forward<Tail>(tail)...);
|
||||||
|
|
Loading…
Reference in a new issue