|
Boost : |
From: ÑÑÑÑам абдÑмаликов (vigosslive2_at_[hidden])
Date: 2019-11-12 17:33:01
> Why did you chose operator>> instead of operator<< ?
Because my intention was to show "control flow transition" which goes in my
case from left to right, thus ">>" and not the other way around "<<".
eswitch( line ) >> // pass control to following "case_"
case_( ... ) >> // pass control to lambda and execute if case_ was matched
[]{...} >> // pass control to "falling_option"
fallthrough_ >> ...;
> // I think the choice is arbitrary and therefore hard to remember.
Nope, it was intentionally. Also I had on my mind following syntax with
pipes "|":
eswitch( line ) |
case_( "^.+ 200 .+$"_r, []{...} ) |
case_( "^.+: .+$"_r, []{...} ) |
default_( []{...} );
> I don't think one should replace the switch...
This sentence confuses me. What do you mean?
You're either saying that we shouldn't try to extend "switch" anyhow or you
meant something else.
In case of( "switch shouldn't be extended..." ), then please explain your
position in more details? Otherwise it sounds like: "I just don't like it".
What I see everywhere, people actually extend "switch", for instance:
"Swift", "C#", "Java", "JavaScript", "LLVM StringSwitch" and I think there
is even more.
I think there is a reason for that, because "switch" is much convenient and
more readable then "if-elseif-else" in some cases.
By the way syntax isn't a problem, I can change it.
Regards
RAbdumalikov
вÑ, 12 ноÑб. 2019 г. в 12:32, Hans Dembinski <hans.dembinski_at_[hidden]>:
> > I don't like this syntax, it is awkward and making the code less
> readable.
> >
> > 1) You are replacing a normal switch, which may be limited in its
> abilities but is well known even to beginners with something that has a
> rather unintuitive syntax. The shift operators are associated to streaming
> in C++ these days, but you use them differently here. Someone who reads
> this code who is not familiar with eswitch will not immediately understand
> this. Why did you chose operator>> instead of operator<< ? I think the
> choice is arbitrary and therefore hard to remember.
> >
> > 2) Your syntax requires one to type a lot of characters. I don't think
> one should replace the switch but if one did, the following syntax would be
> more economic and easier to remember, because it is less arbitrary
> >
> > eswitch( value, case(match1), lambda1, case(match2), lambda2 , ⦠,
> default(), lambdaN );
>
> PS: I forgot to replace `case` by `case_` and `default` by `default_` but
> you get the idea.
>
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk