|
Boost : |
From: Marco (mrcekets_at_[hidden])
Date: 2007-04-17 10:42:42
On Mon, 16 Apr 2007 23:08:42 +0200, Douglas Gregor <doug.gregor_at_[hidden]>
wrote:
> Hello,
>
> On Apr 16, 2007, at 3:33 PM, Marco wrote:
>> I gave a glance to the papers about variadic templates and I didn't
>> see
>> examples using a construct such as f(args)... where args is a function
>> parameter pack; so I guess that the following code it's illegal:
>
> The specification of variadic templates is the authority on what can
> and can't be done with them. The compiler, and the examples in the
> papers, just help to illustrate some of the capabilities. In this
> case...
>
>> template< typename T >
>> T max( T x )
>> {
>> return x;
>> }
>>
>> template< typename T, typename... Args >
>> // where are_same<T, Args...>
>> T max( T x, T y, Args... args )
>> {
>> return std::max( x, max( y, args... ) );
>> }
>>
>>
>> // #1
>> template< typename T, typename... Args >
>> // where are_same<T, Args...>
>> T max_abs( T x, T y, Args... args )
>> {
>> // this is the (probably) illegal construct:
>> return max( abs(x), abs(y), abs(args)... );
>> // I'd like that "abs(args)..." expands to "abs(arg1), ... ,abs
>> (argN)"
>> }
>
> Sure, that's fine.
>
>> What's the rationale behind such a design choice ?
>
> It's a great idea, so we did it :)
>
Great! I had missed that patterned pack expansion works with function
parameter packs too.
I try to dare something more, now.
Has it been taken in consideration to provide a typedef type pack defined
throught a template parameter pack ? That is, something like:
template< typename... Args >
class
{
typedef typename Args::value_type value_types;
// or the following more explicit syntax:
// typedef... typename Args::value_type value_types;
void f( value_types... args );
};
Regards,
Marco
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk