Help with Code Validation of Variadic templates
Larry Evans
cppljevans@suddenlink.net
Mon Aug 17 05:08:00 GMT 2009
On 08/16/09 09:32, Larry Evans wrote:
> On 12/07/07 15:12, Rene Buergel wrote:
>> I'm currently playing around using mainline with the variadic template
>> feature and would like to hear some comments on code gcc is rejecting.
>>
>> #1:
>> =====
>> 1 template<typename T, T a, T... Args> T max()
>> 2 {
>> 3 return a > max<T, Args>() ? a : max<T, Args>();
>> 4 };
>> 5
>> 6 template<typename T, T a, T b>T max()
>> 7 {
>> 8 return a > b ? a : b;
>> 9 };
>>
>> int main()
>> {
>> unsigned int a = max<unsigned int, 3, 2>();
>> unsigned int a = max<unsigned int, 3, 2, 5>();
>> }
>>
>> =====
>> Using the non-variadic template, everything works fine. With the
>> variadic templates, gcc issues an error in line 3:
>> error: parameter packs not expanded with `...':
>> note: 'Args'
> [snip]
> I think this is an instance of bug 40092:
[snip]
OOPS. It's unrealted to bug 40092.
Part of the problem is Args needs to be expanded as follows:
Args...
I think *maybe* the other problem is template function specialization.
Anyway, the workaround is to use template class specializations
as shown in the attached.
HTH.
-Larry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: maxv.cpp
Type: text/x-c++src
Size: 533 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20090817/a4209e1f/attachment-0001.bin>
More information about the Gcc-help
mailing list