Boost logo

Boost :

From: Doug Gregor (dgregor_at_[hidden])
Date: 2007-09-20 14:03:05

On Sep 20, 2007, at 12:59 PM, Peter Bindels wrote:

> Hello,
> On 17/04/2007, Douglas Gregor <doug.gregor_at_[hidden]> wrote:
>> On Apr 17, 2007, at 3:42 PM, Marco wrote:
>>> 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 );
>>> };
>> Yes, it's been taken into consideration, but it does not work.
> Sorry to resurrect an old thread, but I was wondering why this doesn't
> work and whether it's been changed?

It has not and will not be changed.

It doesn't work because one would not be able to know when a
dependent name is actually a parameter pack. Here's a short example:

// This code is ill-formed
template<typename... Types>
struct Foo {
        typedef Types... types;

struct Bar {
        typedef Bar types;

template<typename T>
struct Storage
   typename T::types values; // problem: is T::types a parameter pack
or not?

What is typename T::types, a type or a parameter pack of types? We
absolutely have to know when the process the template whether this
construct is a parameter pack or not, because it affects how pack
expansions are processed. However, instantiating Storage with
Foo<int, float> makes T::types a parameter pack, while instantiating
Storage with Bar makes T::types a single type.

The "fix" for this is to do the same thing that "typename" does for
"typename T::foo"... "typename" was added because the compiler can't
tell whether T::foo is a a value or a type. We would need something

        typename... T::types

to that say T::types is a type parameter pack. We'd need the same
thing for value parameters packs and anything else that could be a
parameter pack. It's not impossible to introduce such an extension,
but doing so drastically increases the syntactic cost of variadic
templates, and the addition of yet new things to worry about with
dependent names makes variadic templates harder to use. For all
these additions, you don't actually gain any expressive power:

        tuple<Types...> values;

does basically the same thing as the requested functionality.\

        - Doug

Boost list run by bdawes at, gregod at, cpdaniel at, john at