Thread overview
Alias template parameters do not allow plain old data types
Jul 15, 2004
Cabal
Jul 15, 2004
Andrew Edwards
Jul 16, 2004
Cabal
Jul 16, 2004
Bent Rasmussen
Jul 20, 2004
Walter
July 15, 2004
You cannot specify a primitive data type for a template parameter which is defined as an alias.

Thanks to Bent Rasmussen for the simplified example case and reference to the D spec. I cut down Bent's simplified version even more. Error at the bottom.

Spec:
"Alias parameters enable templates to be parameterized with any type of D
symbol, including global names, type names, module names, template names,
and template instance names."

Test:
,----[  ]
|
| template Test(alias T) {}
| alias Test!(bit) x;
|
`----

Error:
template instance Test!(int) does not match any template declaration
July 15, 2004
Cabal wrote:
> You cannot specify a primitive data type for a template parameter which is
> defined as an alias.
> 
> Thanks to Bent Rasmussen for the simplified example case and reference to
> the D spec. I cut down Bent's simplified version even more. Error at the
> bottom.
> 
> Spec:
> "Alias parameters enable templates to be parameterized with any type of D
> symbol, including global names, type names, module names, template names,
> and template instance names."
> 
> Test:
> ,----[  ]
> | | template Test(alias T) {}
> | alias Test!(bit) x;
> | `----
> 
> Error:
> template instance Test!(int) does not match any template declaration

That's not a bug, just improper usage.
should be:
,----[  ]
|
| template Test(alias T) {}
| int x; // variable can be of any type (structs and classes included)
| alias Test!(x) aint;
|
`----

or:

,----[  ]
|
| template Test(T) {}
| alias Test!(int) x;
|
`----

Andrew
July 16, 2004
The spec states 'type names'. 'int' is a type name - afaiks there is nothing that specifies the the parameter must be an instance of a type for alias to work as you have said. Class and template type name specifiers work just fine with alias parameters - only primitive type typenames fail.

Andrew Edwards wrote:

> 
> That's not a bug, just improper usage.
> should be:
> ,----[  ]
> |
> | template Test(alias T) {}
> | int x; // variable can be of any type (structs and classes included)
> | alias Test!(x) aint;
> |
> `----
> 
> or:
> 
> ,----[  ]
> |
> | template Test(T) {}
> | alias Test!(int) x;
> |
> `----
> 
> Andrew

July 16, 2004
> The spec states 'type names'. 'int' is a type name - afaiks there is
nothing
> that specifies the the parameter must be an instance of a type for alias
to
> work as you have said. Class and template type name specifiers work just fine with alias parameters - only primitive type typenames fail.

The spec. example that proves this interpretation correct:

class Foo
{
    static int p;
}

template Bar(alias T)
{
    alias T.p q;
}

void test()
{
    alias Bar!(Foo) bar;
    bar.q = 3; // sets Foo.p to 3
}

I thought I had misinterpreted that first paragraph in the alias section of the spec.

> Andrew Edwards wrote:
>
> >
> > That's not a bug, just improper usage.
> > should be:
> > ,----[  ]
> > |
> > | template Test(alias T) {}
> > | int x; // variable can be of any type (structs and classes included)
> > | alias Test!(x) aint;
> > |
> > `----
> >
> > or:
> >
> > ,----[  ]
> > |
> > | template Test(T) {}
> > | alias Test!(int) x;
> > |
> > `----
> >
> > Andrew
>


July 20, 2004
"Cabal" <cabalN05P4M@myrealbox.com> wrote in message news:cd83h9$31fl$1@digitaldaemon.com...
> The spec states 'type names'. 'int' is a type name - afaiks there is
nothing
> that specifies the the parameter must be an instance of a type for alias
to
> work as you have said. Class and template type name specifiers work just fine with alias parameters - only primitive type typenames fail.

Sorry for the confusion. 'bit' is not a type name, but a keyword. A type name would be a typedef'd name, an alias name for a type, a class name, a struct name, etc.