Re: Variadic Template expansion
Am 22.05.2011 23:13, schrieb Arthur Tchaikovsky:
template<class... T1>
struct Are_signed;
template<class T,class... T1>
struct Are_signed<T,T1...>
{
static const bool value = std::is_signed<T>::value&&
Are_signed<T,T1...>::value;//why Are_signed<T,T1...>::value not
Are_signed<T1...>::value?
};
I don't know, so why not fixing the obvious error?
template<class T>
struct Are_signed<T>
{
static const bool value = std::is_signed<T>::value;
};
Where I have problem with is why in partial specialization I'm still
providing parameter T? I've tried to "unpack it" on the piece of paper
and just can't understand how it works.
It doesn't work.
Here is how I've tried to unpack some arguments:
int main()
{
Are_signed<int,bool>::value;
}
So having:
Are_signed<int,bool>::value;
I would go to partial specialization
template<class T,class... T1>
struct Are_signed<T,T1...>
and would have inside of it:
static const bool value = std::is_signed<int>::value&&
Are_signed<int,bool>::value;//but here I'm providing second time int
as a argument
Could anyone please "rewrite" it for me step by step each recursive
call with those arguments and show me how it works.
Your analysis is correct: The code above cannot work and must be fixed.
In other words: You understand the problem of the code.
Your description implies that you are using a compiler that accepts the
original code. This must be a buggy version, the code would end in an
infinite recursion. It might simply be that this manifests as a silent
compiler problem. This is legal behaviour because your code undergoes
undefined behaviour by the strict wording of the standard, but the
diagnostic of the compiler could be improved, so to say. The normative
wording for this situation is given in the FDIS, 14.7.1p15:
"There is an implementation-defined quantity that specifies the limit on
the total depth of recursive instantiations, which could involve more
than one template. The result of an infinite recursion in instantiation
is undefined."
HTH & Greetings from Bremen,
Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]