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 {
|
|
|
|
template<std::size_t N, typename Head, typename... Tail>
|
2012-01-10 14:57:46 +00:00
|
|
|
struct tppack_at_impl_1 {
|
2012-01-09 12:32:51 +00:00
|
|
|
public:
|
2012-01-12 05:11:46 +00:00
|
|
|
typedef typename sprout::detail::tppack_at_impl_1<N - 1, Tail...>::type type;
|
2012-01-09 12:32:51 +00:00
|
|
|
};
|
|
|
|
template<typename Head, typename... Tail>
|
2012-01-10 14:57:46 +00:00
|
|
|
struct tppack_at_impl_1<0, Head, Tail...> {
|
2012-01-09 12:32:51 +00:00
|
|
|
public:
|
|
|
|
typedef Head type;
|
|
|
|
};
|
2012-01-10 14:57:46 +00:00
|
|
|
template<
|
|
|
|
std::size_t N,
|
2012-01-12 05:11:46 +00:00
|
|
|
typename... Args
|
2012-01-10 14:57:46 +00:00
|
|
|
>
|
|
|
|
struct tppack_at_impl
|
|
|
|
: public sprout::detail::tppack_at_impl_1<N, Args...>
|
2012-01-12 05:11:46 +00:00
|
|
|
{
|
|
|
|
static_assert(N < sizeof...(Args), "N < sizeof...(Args)");
|
|
|
|
};
|
2012-01-09 12:32:51 +00:00
|
|
|
} // namespace detail
|
|
|
|
template<std::size_t N, typename... Args>
|
|
|
|
struct tppack_at
|
|
|
|
: public sprout::detail::tppack_at_impl<N, Args...>
|
|
|
|
{};
|
|
|
|
|
|
|
|
//
|
|
|
|
// fppack_at
|
|
|
|
//
|
|
|
|
namespace detail {
|
|
|
|
template<
|
2012-10-05 15:58:56 +00:00
|
|
|
std::size_t N, typename R, typename Head, typename... Tail,
|
2012-01-12 05:11:46 +00:00
|
|
|
typename sprout::enabler_if<N == 0>::type = sprout::enabler
|
2012-01-09 12:32:51 +00:00
|
|
|
>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR R
|
|
|
|
fppack_at_impl(Head&& head, Tail&&... tail) {
|
2012-01-09 12:32:51 +00:00
|
|
|
return sprout::forward<Head>(head);
|
|
|
|
}
|
|
|
|
template<
|
2012-10-05 15:58:56 +00:00
|
|
|
std::size_t N, typename R, typename Head, typename... Tail,
|
2012-01-12 05:11:46 +00:00
|
|
|
typename sprout::enabler_if<N != 0>::type = sprout::enabler
|
2012-01-09 12:32:51 +00:00
|
|
|
>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR R
|
|
|
|
fppack_at_impl(Head&& head, Tail&&... tail) {
|
2012-01-09 12:32:51 +00:00
|
|
|
return sprout::detail::fppack_at_impl<N - 1, R>(sprout::forward<Tail>(tail)...);
|
|
|
|
}
|
|
|
|
} // namespace detail
|
|
|
|
template<std::size_t N, typename... Args>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename sprout::tppack_at<N, Args&&...>::type
|
|
|
|
fppack_at(Args&&... args) {
|
2012-01-09 12:32:51 +00:00
|
|
|
return sprout::detail::fppack_at_impl<
|
|
|
|
N,
|
|
|
|
typename sprout::tppack_at<N, Args&&...>::type
|
|
|
|
>(sprout::forward<Args>(args)...);
|
|
|
|
}
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_UTILITY_PACK_HPP
|