Multiple Specialization?
Paul Findlay
r.lph50+d at gmail.com
Sat Dec 23 02:01:25 PST 2006
Xinok wrote:
> I don't like the idea of using parenthesis or braces.
> I'm trying to create a design which wouldn't require adding a new syntax to D.
>
> I really like the idea of using tuples, that is if multiple specialization were to
> be added to D.
This is an idea I had one walk.. using something like a static switch. I
thought this would be a more natural step for D to get some pattern
matching on template arguments.
So from code I have seen in minid (which brilliant):
public int write(T)(MDState s)
{
MDFile i = cast(MDFile)s.getInstanceParam(0, this);
T val;
static if(is(T == ubyte) || is(T == ushort) || is(T == int))
val = s.getIntParam(1);
else static if(is(T == float))
val = s.getFloatParam(1);
else static if(is(T == char) || is(T == wchar) || is(T == dchar))
val = s.getCharParam(1);
//.. snip
return 0;
}
a static switch version:
public int write(T)(MDState s)
{
MDFile i = cast(MDFile)s.getInstanceParam(0, this);
T val;
static switch(T) {
case(ubyte): case(ushort): case(int):
val = s.getIntParam(1);
break;
case(float):
val = s.getFloatParam(1);
break;
case(char): case(wchar): case(dchar):
val = s.getCharParam(1);
break;
}
//.. snip
return 0;
}
and I imagined having static switch and case been able to handle type
tuples if for example the function prototype was
public int write(T...)(MDState s)
// no example because I am lazy
Does this make sense?
- Paul
More information about the Digitalmars-d
mailing list