Skip to content

Commit

Permalink
Simplified selection of values
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed Oct 12, 2015
1 parent 6556ef8 commit 1f3c6f9
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions include/tao/seq/select.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,31 @@
#define TAOCPP_SEQUENCES_INCLUDE_SELECT_HPP

#include <cstddef>
#include <utility>
#include <type_traits>

#include "make_integer_sequence.hpp"
#include "sum.hpp"
#include "integer_sequence.hpp"

namespace tao
{
namespace seq
{
namespace impl
{
template< std::size_t, typename S, typename = make_index_sequence< S::size() > >
struct select;

template< std::size_t I, typename T, T... Ns, std::size_t... Is >
struct select< I, integer_sequence< T, Ns... >, index_sequence< Is... > >
: seq::sum< T, ( ( Is == I ) ? Ns : 0 )... >
template< typename T, T... Ns >
struct values
{
static_assert( I < sizeof...( Is ), "tao::seq::select<I, S>: I is out of range" );
static constexpr T data[ sizeof...( Ns ) ] = { Ns... };
};
}

template< std::size_t I, typename T, T... Ns >
struct select
: impl::select< I, integer_sequence< T, Ns... > >
: std::integral_constant< T, impl::values< T, Ns... >::data[ I ] >
{};

template< std::size_t I, typename T, T... Ns >
struct select< I, integer_sequence< T, Ns... > >
: impl::select< I, integer_sequence< T, Ns... > >
: select< I, T, Ns... >
{};
}
}
Expand Down

0 comments on commit 1f3c6f9

Please sign in to comment.