2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2014-01-08 07:48:12 +00:00
|
|
|
Copyright (c) 2011-2014 Bolero MURAKAMI
|
2013-08-08 09:54:33 +00:00
|
|
|
https://github.com/bolero-MURAKAMI/Sprout
|
|
|
|
|
|
|
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
=============================================================================*/
|
2012-01-09 12:32:51 +00:00
|
|
|
#ifndef SPROUT_UTILITY_PACK_HPP
|
|
|
|
#define SPROUT_UTILITY_PACK_HPP
|
|
|
|
|
|
|
|
#include <sprout/config.hpp>
|
2014-04-30 07:30:26 +00:00
|
|
|
#include <sprout/workaround/std/cstddef.hpp>
|
2012-01-09 12:32:51 +00:00
|
|
|
#include <sprout/utility/forward.hpp>
|
2013-11-29 13:21:07 +00:00
|
|
|
#include <sprout/type/type_tuple.hpp>
|
2013-11-22 12:11:08 +00:00
|
|
|
#include <sprout/type_traits/integral_constant.hpp>
|
2014-03-29 00:16:43 +00:00
|
|
|
#include <sprout/type_traits/identity.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 {
|
|
|
|
//
|
2013-11-29 13:21:07 +00:00
|
|
|
// pack_element
|
2012-01-09 12:32:51 +00:00
|
|
|
//
|
2013-04-06 04:06:51 +00:00
|
|
|
template<std::size_t I, typename... Args>
|
2013-11-29 13:21:07 +00:00
|
|
|
struct pack_element
|
|
|
|
: public std::tuple_element<I, sprout::types::type_tuple<Args...> >
|
2013-04-06 04:06:51 +00:00
|
|
|
{};
|
|
|
|
|
|
|
|
//
|
2013-11-29 13:21:07 +00:00
|
|
|
// pack_element_c
|
2013-04-06 04:06:51 +00:00
|
|
|
//
|
|
|
|
template<std::size_t I, typename T, T... Args>
|
2013-11-29 13:21:07 +00:00
|
|
|
struct pack_element_c
|
|
|
|
: public sprout::pack_element<I, sprout::integral_constant<T, Args>...>::type
|
2012-01-09 12:32:51 +00:00
|
|
|
{};
|
|
|
|
|
|
|
|
//
|
2013-11-29 13:21:07 +00:00
|
|
|
// pack_get
|
2012-01-09 12:32:51 +00:00
|
|
|
//
|
|
|
|
namespace detail {
|
2013-11-30 04:16:30 +00:00
|
|
|
template<typename Tup>
|
|
|
|
struct pack_get_helper;
|
|
|
|
template<typename... Args>
|
|
|
|
struct pack_get_helper<sprout::types::type_tuple<Args...> > {
|
2013-12-03 13:17:49 +00:00
|
|
|
template<typename Head, typename... Tail>
|
|
|
|
static SPROUT_CONSTEXPR Head&&
|
|
|
|
eval(Args&&..., Head&& head, Tail&&...) {
|
2014-02-22 07:32:51 +00:00
|
|
|
return SPROUT_FORWARD(Head, head);
|
2013-11-30 04:16:30 +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>
|
2013-11-29 13:21:07 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename sprout::pack_element<I, Args&&...>::type
|
|
|
|
pack_get(Args&&... args) {
|
2013-11-30 04:16:30 +00:00
|
|
|
return sprout::detail::pack_get_helper<
|
|
|
|
typename sprout::types::detail::tuple_take<I, sprout::types::type_tuple<Args...> >::type
|
2014-02-22 07:32:51 +00:00
|
|
|
>::eval(SPROUT_FORWARD(Args, args)...);
|
2012-01-09 12:32:51 +00:00
|
|
|
}
|
2014-03-29 00:16:43 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// head_element
|
|
|
|
//
|
|
|
|
template<typename Head, typename... Tail>
|
|
|
|
struct head_element
|
|
|
|
: public sprout::identity<Head>
|
|
|
|
{};
|
|
|
|
|
|
|
|
//
|
|
|
|
// head_get
|
|
|
|
//
|
|
|
|
template<typename Head, typename... Tail>
|
|
|
|
inline SPROUT_CONSTEXPR Head&&
|
2014-03-31 08:18:22 +00:00
|
|
|
head_get(Head&& head, Tail&&...) {
|
2014-03-29 00:16:43 +00:00
|
|
|
return SPROUT_FORWARD(Head, head);
|
|
|
|
}
|
2012-01-09 12:32:51 +00:00
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_UTILITY_PACK_HPP
|