From: Rene Buergel <rbuergel@HTWM.De>
To: gcc-help@gcc.gnu.org
Subject: Help with Code Validation of Variadic templates
Date: Fri, 07 Dec 2007 21:10:00 -0000 [thread overview]
Message-ID: <4759B730.2000504@htwm.de> (raw)
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?
next reply other threads:[~2007-12-07 21:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-07 21:10 Rene Buergel [this message]
2009-08-17 3:18 ` Larry Evans
2009-08-17 5:08 ` Larry Evans
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4759B730.2000504@htwm.de \
--to=rbuergel@htwm.de \
--cc=gcc-help@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).