public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Help with Code Validation of Variadic templates
@ 2007-12-07 21:10 Rene Buergel
  2009-08-17  3:18 ` Larry Evans
  0 siblings, 1 reply; 3+ messages in thread
From: Rene Buergel @ 2007-12-07 21:10 UTC (permalink / raw)
  To: gcc-help

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?

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-08-16 15:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-07 21:10 Help with Code Validation of Variadic templates Rene Buergel
2009-08-17  3:18 ` Larry Evans
2009-08-17  5:08   ` Larry Evans

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).