Connecting Tech Pros Worldwide Help | Site Map

List parameters

 
LinkBack Thread Tools Search this Thread
  #1  
Old October 21st, 2006, 11:45 PM
user@domain.invalid
Guest
 
Posts: n/a
Default List parameters

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, 01:35 AM
David Harmon
Guest
 
Posts: n/a
Default 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, 03:05 AM
Lahsen
Guest
 
Posts: n/a
Default 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, 11:05 AM
loufoque
Guest
 
Posts: n/a
Default 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, 11:05 AM
loufoque
Guest
 
Posts: n/a
Default 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.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.