sprout/utility/enabler_if.hpp 追加

This commit is contained in:
bolero-MURAKAMI 2012-01-12 14:11:46 +09:00
parent e11da4400b
commit 86073fea83
3 changed files with 31 additions and 23 deletions

View file

@ -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

View 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

View file

@ -5,7 +5,7 @@
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/utility/enabler.hpp>
#include <sprout/utility/enabler_if.hpp>
namespace sprout {
//
@ -15,7 +15,7 @@ namespace sprout {
template<std::size_t N, typename Head, typename... Tail>
struct tppack_at_impl_1 {
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>
struct tppack_at_impl_1<0, Head, Tail...> {
@ -24,18 +24,13 @@ namespace sprout {
};
template<
std::size_t N,
typename... Args,
typename std::enable_if<(N < sizeof...(Args))>::type*& = sprout::enabler
typename... Args
>
struct tppack_at_impl
: public sprout::detail::tppack_at_impl_1<N, Args...>
{};
template<
std::size_t N,
typename... Args,
typename std::enable_if<(N >= sizeof...(Args))>::type*& = sprout::enabler
>
struct tppack_at_impl {};
{
static_assert(N < sizeof...(Args), "N < sizeof...(Args)");
};
} // namespace detail
template<std::size_t N, typename... Args>
struct tppack_at
@ -51,7 +46,7 @@ namespace sprout {
typename R,
typename Head,
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) {
return sprout::forward<Head>(head);
@ -61,7 +56,7 @@ namespace sprout {
typename R,
typename Head,
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) {
return sprout::detail::fppack_at_impl<N - 1, R>(sprout::forward<Tail>(tail)...);