taking the answer from here : iterate over tuple regarding printing std::tuple
components, here is the code :
template<std::size_t I = 0, typename... Tp>
typename std::enable_if<I == sizeof...(Tp), void>::type
print(const std::tuple<Tp...>& t)
{ }
template<std::size_t I = 0, typename... Tp>
typename std::enable_if<I < sizeof...(Tp), void>::type
print(const std::tuple<Tp...>& t)
{
std::cout << std::get<I>(t) << std::endl;
print <i, Tp...> (t);
}
this compiles and works perfectly on GCC, but fails to compile on VC++ (I use visual studio 2013). the error I'm gettting :
Error 4 error C2893: Failed to specialize function template 'std::enable_if<I==1,void>::type print(const std::tuple<_Types1...> &)'
Error 3 error C2770: invalid explicit template argument(s) for 'std::enable_if<I<1,void>::type print(const std::tuple<_Types1...> &)'
appearntly there is a documented bug on C2770 when using std::enable_if
with explicit template-arguments. some developers recommended using const int
as pre-argument for the template as
const int i = I+1;
print<i,Tp...>(t);
but this does not work either.
there were other solutions also such as use some macros , but they fail too.
does someone have a work around it ? I searched for a solution but found none that actually works.
thanks.