Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-recursive at_index implementation #2017

Merged
merged 1 commit into from
Mar 7, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 27 additions & 9 deletions hpx/util/detail/pack.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2014 Agustin Berge
// Copyright (c) 2014-2016 Agustin Berge
//
// 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)
Expand Down Expand Up @@ -110,19 +110,37 @@ namespace hpx { namespace util { namespace detail
{};

///////////////////////////////////////////////////////////////////////////
template <std::size_t I, typename ...Ts>
struct at_index;
template <std::size_t I, typename T>
struct indexed
{
typedef T type;
};

template <typename Ts, typename Is>
struct indexer;

template <std::size_t I, typename T, typename ...Ts>
struct at_index<I, T, Ts...>
: at_index<I - 1, Ts...>
template <typename ...Ts, std::size_t ...Is>
struct indexer<pack<Ts...>, pack_c<std::size_t, Is...>>
: indexed<Is, Ts>...
{};

template <typename T, typename ...Ts>
struct at_index<0, T, Ts...>
template <std::size_t I, typename Ts>
struct at_index_impl
{
typedef T type;
static empty check_(...);

template <std::size_t J, typename T>
static indexed<J, T> check_(indexed<J, T> const&);

typedef decltype(check_<I>(indexer<
Ts, typename make_index_pack<Ts::size>::type
>())) type;
};

template <std::size_t I, typename ...Ts>
struct at_index
: at_index_impl<I, pack<Ts...> >::type
{};
}}}

#endif