Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > List parameters

Reply
Thread Tools

List parameters

 
 
user@domain.invalid
Guest
Posts: n/a
 
      10-22-2006
Hi,

I try this code:

template <typename T> inline
T const& max(T const& a, T const& b)
{
return a<b?b:a;
}

template <typename T, ... list> inline
T const& max(T const& a, T const& b, list const& x)
{
return max(a, max(b, x));
}


But it not compile.
I have this message:
"error: expected identifier before '...' token"

I saw this sample in book "c++ templates: the complete guide"
i use wxWidgets with gcc compiler.

Is this code legal? is it compile?
If no how use list parameters in template?

Thunks
 
Reply With Quote
 
 
 
 
David Harmon
Guest
Posts: n/a
 
      10-22-2006
On Sun, 22 Oct 2006 02:06:20 +0200 in comp.lang.c++,
lid wrote,
> template <typename T, ... list> inline
> T const& max(T const& a, T const& b, list const& x)
> {
> return max(a, max(b, x));
> }


No, the ... is not at all allowed there.
This is from chapter 13, "Future Directions", where the authors are
discussing things that don't exist yet, but might in the future,
right???

 
Reply With Quote
 
 
 
 
Lahsen
Guest
Posts: n/a
 
      10-22-2006
David Harmon a écrit :
> On Sun, 22 Oct 2006 02:06:20 +0200 in comp.lang.c++,
> lid wrote,
>
>> template <typename T, ... list> inline
>> T const& max(T const& a, T const& b, list const& x)
>> {
>> return max(a, max(b, x));
>> }

>
>
> No, the ... is not at all allowed there.
> This is from chapter 13, "Future Directions", where the authors are
> discussing things that don't exist yet, but might in the future,
> right???
>


Ok,
Thunks.

I try to do it with typeListe technique in modern c++.

But there'is function ellipsis like:

void f(int ...);

f(1, 2, 3);
f(45, 68 ,2 ,64 ,359;

that compile. But it's not easy to use argument of this function.

 
Reply With Quote
 
loufoque
Guest
Posts: n/a
 
      10-22-2006
Lahsen wrote:
>
> But there'is function ellipsis like:
>
> void f(int ...);
>
> f(1, 2, 3);
> f(45, 68 ,2 ,64 ,359;
>
> that compile. But it's not easy to use argument of this function.


That's a runtime thing which isn't type-safe at all.
It should be avoided.
 
Reply With Quote
 
loufoque
Guest
Posts: n/a
 
      10-22-2006
lid wrote:
> Hi,
>
> I try this code:
>
> template <typename T> inline
> T const& max(T const& a, T const& b)
> {
> return a<b?b:a;
> }
>
> template <typename T, ... list> inline
> T const& max(T const& a, T const& b, list const& x)
> {
> return max(a, max(b, x));
> }
>
>
> But it not compile.


You might want to play around with variadic templates, a proposal for
the next C++ standard which will allow what you want.
There is already a patch to implement it in GCC.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
skipping template parameters inside template parameters kito C++ 2 09-26-2010 12:04 AM
Class Member Data and Member Function Parameters - Should Parameters Be Data Members? Jason C++ 2 05-13-2006 07:11 AM
does a "parameters"-parameter overwrite the "parameters"-object? Florian Loitsch Javascript 11 03-15-2005 03:33 PM
Difference Between List x; and List x(); , if 'List' is a Class? roopa C++ 6 08-27-2004 06:18 PM
Servlet parameters different from the command line parameters? Jonck van der Kogel Java 2 05-26-2004 11:34 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57