Is there an easy way to mimic generics with an accept method of a visitor pattern?

Paul Backus snarwin at gmail.com
Thu Feb 18 15:11:44 UTC 2021


On Thursday, 18 February 2021 at 14:51:09 UTC, vitamin wrote:
> On Thursday, 18 February 2021 at 14:43:43 UTC, Paul Backus 
> wrote:
>>
>> I don't see what this buys you compared to sticking with one 
>> or the other, but you are correct that it is technically 
>> possible.
>
> It infer function atributes (pure, nothrow @nogc @safe) for 
> "visitor" and let you use classes and inheritence.
> With standard visitor pattern you need PureVisitor. 
> NothrowVisitor, PureNothrowVisitor...

It seems to me like you would also get those benefits by just 
using a discriminated union, without the classes.


More information about the Digitalmars-d-learn mailing list