Shortcuts
James Dunne
james.jdunne at gmail.com
Sun Feb 26 08:47:08 PST 2006
Trevor Parscal wrote:
> 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
Hmm, I don't know. That removes a lot of typing information. Also,
dynamic memory is allocated per each function call, which makes it look
less appealing, not to mention non-performant.
And finally, the list method is kinda scary - a silent failure case
hidden away in your casting on pointers.
What's to be gained here?
--
Regards,
James Dunne
More information about the Digitalmars-d
mailing list