dimanche 21 décembre 2014

Create a variadic template from a constexpr array

Let's say we have the following type



template <bool... Values>
struct foo{};


I want to create a variadic template from a constexpr array bool tab[N]. In other words, I want to do something like:



constexpr bool tab[3] = {true,false,true};
using ty1 = foo<tab[0], tab[1], tab[2]>;


But I want to do it programmatically. For now, I've tried the following:



template <std::size_t N, std::size_t... I>
auto
mk_foo_ty(const bool (&tab)[N], std::index_sequence<I...>)
{
// error: template argument for template type parameter must be a type
return foo<tab[I]...>{};
}

// error (see mk_foo_ty)
using ty2 = decltype(mk_ty(tab, std::make_index_sequence<3>{}));

// error: expected '(' for function-style cast or type construction
using ty3 = foo<(tab[std::make_index_sequence<3>])...>;


I'm not even sure if it's possible. Maybe resorting to something like Boost.Preprocessor, but I don't like the idea. So, does anyone have an idea? Thanks!


Aucun commentaire:

Enregistrer un commentaire