[Issue 12597] Payload getter for std.typecons.Typedef
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Apr 3 19:13:39 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=12597
tyckesak <josipp at live.de> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |josipp at live.de
--- Comment #17 from tyckesak <josipp at live.de> ---
(In reply to bearophile_hugs from comment #14)
> (In reply to monkeyworks12 from comment #13)
>
> > But casting to TypedefType!(typeof(x)) is always safe,
>
> If it's always safe it shouldn't look dangerous, so it it shouldn't look
> like "cast(" in a textual search.
>
>
> > so if you want such a function, it's trivial to add one yourself.
> > The main problem (getting the underlying type of a Typedef) is solved.
> >
> > auto typedefVal(T)(T val)
> > {
> > return cast(TypedefType!T)val;
> > }
>
> Yes, this ER asks for such safe function in Phobos.
Could this be integrated into the definition of `std.conv.to(T)`?
The module `std.conv` is described as a one-stop-shop for converting
different types into each other, after all.
I see a very clear objective here to safely and explicitly cast the underlying
value to its corresponding type, and the `to` template is very well-suited
for that kind of transformation.
--
More information about the Digitalmars-d-bugs
mailing list