compiling error when c++ variadic template class deducing in VS2015 update 3

  • Thread starter Thread starter LightGoLeft
  • Start date Start date
L

LightGoLeft

Guest
Hello,

I am trying to define a type based on types within a tuple. The code is compiled with c++14 but I met a wired compiling error.

The code is like:

template <class T, std::size_t... I> //T is a type of Tuple of Tuples
struct s {
using type = std::tuple<decltype(
foo<std::tuple_element<I, T>::type>())::type ...>;//here comes the compiling error
s(std::index_sequence<I...>);

};


where foo<Tuple, size_t...>() returns a template class ss:

template <class Tuple, std::size_t... I>
struct ss {
ss(std::index_sequence<I...>);
using type = some_type_related_to_Tuple;
};



Then the compiling error comes:

error C2146: syntax error: missing '>' before identifier 'type'


Then I did the following experiment:

1. I removed ::type behind decltype() in s:

template <class T, std::size_t... I>
struct s {
using type = std::tuple<decltype(
foo<typename std::tuple_element<I, T>::type>()) ...>;
s(std::index_sequence<I...>);
};



Everything worked fine but I got s<>::type = std::tuple<ss<>, ss<>> instead of std::tuple<ss<>::type, ss<>::type>


2. If I define struct s in GNU way of using typename:

template <class T, std::size_t... I>
struct s {
using type = std::tuple<typename decltype(
foo<typename std::tuple_element<I, T>::type::in_value_t>())::type ...>;
s(std::index_sequence<I...>);
};


The code compiled fine with MinGW. However this introduces more error in MSVC like:

error C2027: use of undefined type 'std::tuple_element<& I,T>'


Thanks for any help.

Continue reading...
 
Back
Top