Sprout/sprout/utility/pack.hpp

60 lines
1.8 KiB
C++
Raw Normal View History

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 <cstddef>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
2013-11-29 13:21:07 +00:00
#include <sprout/type/type_tuple.hpp>
#include <sprout/type_traits/integral_constant.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...> > {
template<typename Head, typename... Tail>
static SPROUT_CONSTEXPR Head&&
eval(Args&&..., Head&& head, Tail&&...) {
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
>::eval(sprout::forward<Args>(args)...);
2012-01-09 12:32:51 +00:00
}
} // namespace sprout
#endif // #ifndef SPROUT_UTILITY_PACK_HPP