Help with Code Validation of Variadic templates

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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'
I think, that this code is valid. If not, please point it out to me.


#2:
=====
template<template<typename... Params> class Comp, typename... Params> void f( Params... p)
{
 static_assert( Comp<Params>::value, "" );
}

template <typename T>
class Foo
{
   static const int value=1;
};

int main()
{
       f<Foo, int, int>( );
}

=====
Here I'm not that sure about the validity of the code, my intention was to use tr1/type_traits in macros on ordinary variables instead of types. So, the variadic template f would resolve the type for me. That intended use was something like f<std::tr1::is_same>( _var1, _var2 );, which would compile-time-check, if _var1 and _var2 are exaclty the same type. But i'm not even coming that far, as gcc issues: "error: no matching function for call to 'f()'". Any Ideas, what's wrong here?

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux