Parameterized Structs

Ali Çehreli acehreli at yahoo.com
Thu Mar 3 00:36:41 PST 2011


On 03/03/2011 12:21 AM, Peter Lundgren wrote:

 >>   >>  On 03/02/2011 08:56 PM, Peter Lundgren wrote:

 >>   >>>  struct MyStruct(T, T[] a) {
 >>   >>>        ...
 >>   >>>  }
 >>   >>>
 >>   >>>  but I receive the following error:
 >>   >>>
 >>   >>>  Error: arithmetic/string type expected for value-parameter, 
not T[]

...

 > That's closer, except I want to pass a value parameter (specifically, 
some compile
 > time instance of SomeContainer) instead of a type parameter, but that 
doesn't look
 > like it's supported.

I finally get it! :)

Yes, there are limitations for template value parameters. The spec at

   http://digitalmars.com/d/2.0/template.html#TemplateValueParameter

says:

<quote>
Template value parameter types can be any type which can be statically 
initialized at compile time, and the value argument can be any 
expression which can be evaluated at compile time. This includes 
integers, floating point types, and strings.
</quote>

Ali



More information about the Digitalmars-d-learn mailing list