www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Alias template parameters do not allow plain old data types

reply Cabal <cabalN05P4M myrealbox.com> writes:
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
Jul 15 2004
parent reply Andrew Edwards <ridimz_at yahoo.dot.com> writes:
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
Jul 15 2004
parent reply Cabal <cabalN05P4M myrealbox.com> writes:
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

Jul 16 2004
next sibling parent "Bent Rasmussen" <exo bent-rasmussen.info> writes:
 The spec states 'type names'. 'int' is a type name - afaiks there is

 that specifies the the parameter must be an instance of a type for alias

 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


Jul 16 2004
prev sibling parent "Walter" <newshound digitalmars.com> writes:
"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

 that specifies the the parameter must be an instance of a type for alias

 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.
Jul 20 2004