On Friday, 7 July 2017 at 09:14:56 UTC, Arafel wrote:
[...]
Is there any way to create a shared instance of an anonymous
class?
[...]
If somebody knows how this works / is supposed to work, I'd be
thankful!
[1]: https://dpaste.dzfl.pl/ce2ba93111a0
Yes, but it's round about: you have to instantiate the class as
unshared and then cast it to `shared` [1].
If you look at the grammar [2][3] you'll see why:
NewAnonClassExpression does not support specifying the storage
class for the new instance, as opposed to NewExpression.
Do note, though, that `shared` is pretty much all rough edges
with (virtually) no joy at present and IIRC from DConf2017 it's
in the queue for an overhaul.
[1] https://dpaste.dzfl.pl/35a9a8a1d1f7
[2] https://dlang.org/spec/grammar.html#NewExpression
[3] https://dlang.org/spec/grammar.html#NewAnonClassExpression