Shortcuts
Trevor Parscal
Trevor_member at pathlink.com
Sun Feb 26 08:29:38 PST 2006
I just wrote a new templated shortcut module for Fusion - and I thought I would
suggest inclusion in phobos - since it's so darn handy. Some might think this
isn't their style - but it can be useful in making things look nice and clear
IMHO.
The idea is that you can have "multi" argument properties like...
/////////////////////////////////
class FOO
{
int[] Range(int[] _values)
in
{
asert(_values.length >= 2);
}
body
{
this.start = _values[0];
this.end = _values[1];
return _values;
}
}
/////////////////////////////////
and than you can use the property like...
/////////////////////////////////
foo.Range = pair(1, 10);
/////////////////////////////////
There are 3 shortcuts. all deal with values of a single type.
pair has 2 arguments, and always returns a dynamic array with 2 elements.
trio has 3 arguments, and always returns a dynamic array with 3 elements.
list is variadic, and always returns a dynamic array with at least 1 element.
The code can be seen on the dsource svn...
http://svn.dsource.org/projects/terra/trunk/Fusion/Source/Fusion/Composite.d
The source is free as in beer - just let your buddies know who gave you the
beer!
Thanks,
Trevor Parscal
More information about the Digitalmars-d
mailing list