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

76 lines
2.1 KiB
C++
Raw Normal View History

2012-01-09 12:32:51 +00:00
#ifndef SPROUT_UTILITY_PACK_HPP
#define SPROUT_UTILITY_PACK_HPP
#include <cstddef>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
2012-05-26 15:43:38 +00:00
#include <sprout/type_traits/enabler_if.hpp>
2012-01-09 12:32:51 +00:00
namespace sprout {
//
// tppack_at
//
namespace detail {
2013-04-06 04:06:51 +00:00
template<std::size_t I, typename Head, typename... Tail>
struct tppack_at_impl_1
2013-04-06 04:06:51 +00:00
: public sprout::detail::tppack_at_impl_1<I - 1, Tail...>
{};
2012-01-09 12:32:51 +00:00
template<typename Head, typename... Tail>
struct tppack_at_impl_1<0, Head, Tail...> {
2012-01-09 12:32:51 +00:00
public:
typedef Head type;
};
2013-04-06 04:06:51 +00:00
template<std::size_t I, typename... Args>
struct tppack_at_impl
2013-04-06 04:06:51 +00:00
: public sprout::detail::tppack_at_impl_1<I, Args...>
2012-01-12 05:11:46 +00:00
{
2013-04-06 04:06:51 +00:00
static_assert(I < sizeof...(Args), "I < sizeof...(Args)");
2012-01-12 05:11:46 +00:00
};
2012-01-09 12:32:51 +00:00
} // namespace detail
2013-04-06 04:06:51 +00:00
template<std::size_t I, typename... Args>
2012-01-09 12:32:51 +00:00
struct tppack_at
2013-04-06 04:06:51 +00:00
: public sprout::detail::tppack_at_impl<I, Args...>
{};
//
// tppack_c_at
//
template<std::size_t I, typename T, T... Args>
struct tppack_c_at
: public sprout::tppack_at<I, std::integral_constant<T, Args>...>::type
2012-01-09 12:32:51 +00:00
{};
//
// fppack_at
//
namespace detail {
template<
2013-04-06 04:06:51 +00:00
std::size_t I, typename R, typename Head, typename... Tail,
typename sprout::enabler_if<I == 0>::type = sprout::enabler
2012-01-09 12:32:51 +00:00
>
2012-10-05 15:58:56 +00:00
inline SPROUT_CONSTEXPR R
2013-07-22 13:00:09 +00:00
fppack_at_impl(Head&& head, Tail&&...) {
2012-01-09 12:32:51 +00:00
return sprout::forward<Head>(head);
}
template<
2013-04-06 04:06:51 +00:00
std::size_t I, typename R, typename Head, typename... Tail,
typename sprout::enabler_if<I != 0>::type = sprout::enabler
2012-01-09 12:32:51 +00:00
>
2012-10-05 15:58:56 +00:00
inline SPROUT_CONSTEXPR R
2013-07-22 13:00:09 +00:00
fppack_at_impl(Head&&, Tail&&... tail) {
2013-04-06 04:06:51 +00:00
return sprout::detail::fppack_at_impl<I - 1, R>(sprout::forward<Tail>(tail)...);
2012-01-09 12:32:51 +00:00
}
} // namespace detail
2013-04-06 04:06:51 +00:00
template<std::size_t I, typename... Args>
inline SPROUT_CONSTEXPR typename sprout::tppack_at<I, Args&&...>::type
2012-10-05 15:58:56 +00:00
fppack_at(Args&&... args) {
2012-01-09 12:32:51 +00:00
return sprout::detail::fppack_at_impl<
2013-04-06 04:06:51 +00:00
I,
typename sprout::tppack_at<I, Args&&...>::type
2012-01-09 12:32:51 +00:00
>(sprout::forward<Args>(args)...);
}
} // namespace sprout
#endif // #ifndef SPROUT_UTILITY_PACK_HPP