Parameterized Structs
Steven Schveighoffer
schveiguy at yahoo.com
Thu Mar 3 06:15:46 PST 2011
On Thu, 03 Mar 2011 00:45:05 -0500, Bekenn <leaveme at alone.com> wrote:
> On 3/2/2011 8:56 PM, Peter Lundgren wrote:
>> Where can I go to learn about parameterized structs? I can't seem to
>> find any
>> literature on the subject. In particular, what are you allowed to use
>> as a
>> parameter? I would like to define a struct like so:
>>
>> struct MyStruct(T, T[] a) {
>> ...
>> }
>>
>> but I receive the following error:
>>
>> Error: arithmetic/string type expected for value-parameter, not T[]
>>
>> Are arrays not allowed?
>
> This compiles:
>
> struct MyStruct(T : T[], T a)
> {
> T A = a.dup;
> }
>
> ...but I have yet to figure out how to properly invoke it.
warning to all template novices -- a template compiling simply means it
*PARSES*. You have to instantiate it, in order to verify it is correct.
The compiler cannot possibly know the semantic meaning of a template
without knowing what the parameters are.
I would expect your struct to never instantiate properly, because a.dup is
not a valid static initializer.
-Steve
More information about the Digitalmars-d-learn
mailing list