Recursive Templates
Steven Schveighoffer
schveiguy at yahoo.com
Tue Jul 29 13:15:53 PDT 2008
"llee" wrote
> I'm trying to define an object named Param that has a member named value.
> Value can be either a variable of type T, and array of type T[], or an
> array of other Params.
> Using templates, I could implement the first two cases:
> class Param (T) { T value; ... }
> but I could not handle the recursive case.
enum valuetype
{
T,
Array,
Param
}
class Param(T, valuetype vt = valuetype.T)
{
static if(vt == valuetype.T)
{
T value;
}
else if(vt == valuetype.Array)
{
T[] value;
}
else if(vt == valuetype.Param)
{
Param!(T, vt) value;
}
}
-Steve
More information about the Digitalmars-d
mailing list