static switch
Orvid King
blah38621 at gmail.com
Wed Mar 5 05:34:00 PST 2014
Well, as long as we're talking about language design, 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.
On 3/5/14, Dominikus Dittes Scherkl
<Dominikus.Scherkl at continental-corporation.com> wrote:
> I wonder why there is no static switch (analogue to static if)?
> Because especially if you overload a lot of operators (which is
> done e.g.
> in the definition of complex and bigint) I would think something
> like
>
> T opOpAssign(string op, T)(T x) if(op=="+" || op=="-" || op=="*"
> || op=="/" || op=="%" || op=="^^" || op=="&" || op=="|" ||
> op=="^" || op=="<<" || op==">>" || op==">>>")
> {
> static switch(op)
> {
> case "+":
> case "-":
> ...
> break;
> case "*":
> ...
> }
> }
>
> would look much better than
>
> {
> static if(op=="+" || op == "-")
> {
> ...
> }
> else static if(op == "*")
> {
> ...
> }
> else
> {
> ...
> }
> }
>
More information about the Digitalmars-d
mailing list