static switch

bearophile bearophileHUGS at lycos.com
Wed Mar 5 06:09:31 PST 2014


Orvid King wrote:

> couldn't the first be improved more by allowing something like:
>
> T opOpAssign(string op : in("+", "-", "*", "/", "%", "^^", "&", 
> "|", "^", "<<", ">>", ">>>"), T)(T x)
>
> The `in` there is my attempt to disambiguate between this type 
> of constraint and what I view as the most likely syntax for 
> built-in tuples.

While a static switch could be a little handy (I have desired it 
few times, despite a static foreach is much more needed), there's 
no strong need for that "in", You can use something like 
(untested):

T opOpAssign(string op, T)(T x)
if ("+ - * / % ^^ & | ^ << >> >>>".split.canFind(op))

Bye,
bearophile


More information about the Digitalmars-d mailing list