www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Template specialisations and 'alias'

reply Cabal <cabal myrealbox.com> writes:
The following code gives an error when trying to implement specialisation

*** template instance SpecTest!(Dummy ,0) matches more than one template
declaration

,----[  ]
| 
| template SpecTest(alias T, int n) {
|   alias T X;
| }
| 
| template SpecTest(alias T, int n :0) {
|   alias T X;
| }
| 
| class Dummy {}
| 
| void main() {
|   alias SpecTest!(Dummy, 0).X Y;
| }
| 
`----

If I remove the 'alias' keywords and substitute the Dummy class for 'int',
it all compiles. Any ideas why this should be?

Also, using 'alias' prevents using 'int' (and I presume other primitive
types) as parameters to those templates. Is this intentional? The why's and
wherefore's of using 'alias' in template parameter lists is not well
defined.

Cabal.
Jul 14 2004
next sibling parent Cabal <cabalN05P4M myrealbox.com> writes:
Come on guys n gals! 
Someone must be using templates and specialisation. One of you must have a
clue.
Jul 14 2004
prev sibling parent reply "Bent Rasmussen" <exo bent-rasmussen.info> writes:
I'd post this as a bug, the case can be simplified even further

template Test(alias T, int n : 0) {}
alias Test!(bit,0) x;

The specification states

"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."

The test works if T is not an alias parameter and yet the description says
that type names are valid arguments to alias parameters so I don't know what
else to make of this, other than it is a bug.
Jul 15 2004
parent reply Cabal <cabalN05P4M myrealbox.com> writes:
Thanks Bent, I was beginning to wonder if anyone else was using templates at
all. Your test highlights my second query regarding primitive types not
being able match alias parameters. If you don't mind I'll report 2 separate
bugs with your example being one of them.

Bent Rasmussen wrote:

 I'd post this as a bug, the case can be simplified even further
 
 template Test(alias T, int n : 0) {}
 alias Test!(bit,0) x;
 
 The specification states
 
 "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."
 
 The test works if T is not an alias parameter and yet the description says
 that type names are valid arguments to alias parameters so I don't know
 what else to make of this, other than it is a bug.
Jul 15 2004
parent "Bent Rasmussen" <exo bent-rasmussen.info> writes:
 Thanks Bent, I was beginning to wonder if anyone else was using templates
at
 all. Your test highlights my second query regarding primitive types not
 being able match alias parameters. If you don't mind I'll report 2
separate
 bugs with your example being one of them.
Well now I do, since I was wrong. :-)
Jul 15 2004