How about a Hash template?

Robert Clipsham robert at octarineparrot.com
Fri Apr 29 02:44:05 PDT 2011


On 29/04/2011 10:31, Jacob Carlborg wrote:
> On 2011-04-28 18:20, Andrej Mitrovic wrote:
>> Well, DMD accepts this kind of syntax already:
>>
>> if (value == val1, val2, val3) { }
>>
>> I think this turns the expression value==val1 into a bool, and then
>> turns val2 and val3 into bools and compares against each of them. Or
>> something like that. It's odd and I've never seen it used anywhere.
>>
>> Maybe we could put that syntax into good use.
>
> Wouldn't it be nice if you could do something like this:
>
> if (value == (3 || 4)) {}
>
> And the compiler turns that into:
>
> if (value == 3 || value == 4) {}
>

Using infix operators you can do:

if (value == 3 /or/ 4 /or/ 5)

See tools.base: 
http://dsource.org/projects/scrapple/browser/trunk/tools/tools/base.d#L1093

There are also variations in there for and, map, and others.

-- 
Robert
http://octarineparrot.com/


More information about the Digitalmars-d mailing list