Connecting Tech Pros Worldwide Help | Site Map

List parameters

  #1  
Old October 22nd, 2006, 12:45 AM
user@domain.invalid
Guest
 
Posts: n/a
Hi,

I try this code:

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

template <typename T, ... listinline
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
  #2  
Old October 22nd, 2006, 02:35 AM
David Harmon
Guest
 
Posts: n/a

re: List parameters


On Sun, 22 Oct 2006 02:06:20 +0200 in comp.lang.c++,
user@domain.invalid wrote,
Quote:
> template <typename T, ... listinline
> 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???

  #3  
Old October 22nd, 2006, 04:05 AM
Lahsen
Guest
 
Posts: n/a

re: List parameters


David Harmon a écrit :
Quote:
On Sun, 22 Oct 2006 02:06:20 +0200 in comp.lang.c++,
user@domain.invalid wrote,
>
Quote:
>> template <typename T, ... listinline
>> 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 ,3598);

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

  #4  
Old October 22nd, 2006, 12:05 PM
loufoque
Guest
 
Posts: n/a

re: List parameters


Lahsen wrote:
Quote:
>
But there'is function ellipsis like:
>
void f(int ...);
>
f(1, 2, 3);
f(45, 68 ,2 ,64 ,3598);
>
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.
  #5  
Old October 22nd, 2006, 12:05 PM
loufoque
Guest
 
Posts: n/a

re: List parameters


user@domain.invalid wrote:
Quote:
Hi,
>
I try this code:
>
template <typename Tinline
T const& max(T const& a, T const& b)
{
return a<b?b:a;
}
>
template <typename T, ... listinline
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.
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Single-Linked List in C Atos insights 0 June 15th, 2008 05:58 AM
List Parameters user@domain.invalid answers 0 October 22nd, 2006 12:55 AM
Listing Web Services parameters hulkko123@yahoo.com answers 0 February 13th, 2006 11:15 AM
Listing parameters of the Web Service Hulk answers 0 February 13th, 2006 11:05 AM