Pattern matching via switch?
schveiguy at gmail.com
Tue Mar 17 11:59:36 UTC 2020
On 3/17/20 4:18 AM, Paolo Invernizzi wrote:
> On Sunday, 15 March 2020 at 18:52:01 UTC, Steven Schveighoffer wrote:
>> D doesn't support this natively. The closest you can get is something
>> akin to what aliak wrote (you would need to write something, not sure
>> if Phobos or some package has implemented the feature), or use
>> cascaded if statements:
> I've just given a fast look at the thread, so maybe I'm wrong, but this
>  should be ok for pattern matching using plain and simple Phobos ...
>  https://dlang.org/phobos/std_variant.html#.visit
I think he's looking for object pattern matching. i.e. you give it an
Object, and it runs a block of code based on the derived type.
More information about the Digitalmars-d-learn