On Monday, 26 February 2018 at 19:25:06 UTC, WebFreak001 wrote:
hi, I had an idea from using some C# which I think would be
really cool in D. Basically allow modifying implicit
construction of a type. Right now we only have struct
opAssign/constructor implicit conversion, but this addition
would also add it to classes and make it even more convenient.
[...]
What's your opinion on this? I think it is really useful to
have when interoping with scripting languages or doing
(de)serialization or for these attribute wrappers which are
there because of no function attribute UDAs. I was looking into
implementing this to dmd myself but the code on the implicit
cast checks looks a bit hardcoded for the types that are in
right now and not really suitable to implement this, but maybe
someone with more knowledge about dmd internals can do this
with ease.
This is only a single direction T -> Wrapper and I think this
would actually be enough, but it would maybe be possible to add
@implicit to opCast in the future.
Such implicit conversion was once 'on the table', see this
thread:
https://forum.dlang.org/post/[email protected].
I also think that controlled implicit conversion would be
sometimes useful, notably with wrapper structs. For now, the only
solution is to use templated functions (in some cases, all the
code using wrapper structs has to be templated...). Pragmatism
and cautious design sometimes defeat 'EVIL'.