September 24, 2014
https://issues.dlang.org/show_bug.cgi?id=12597

monkeyworks12@hotmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monkeyworks12@hotmail.com

--- Comment #11 from monkeyworks12@hotmail.com ---
I think this enhancement request should be closed now that https://github.com/D-Programming-Language/phobos/pull/2116 has been merged. With that PR, your first example now becomes:

void main() {
    import std.typecons: Typedef;
    import std.math: sin;
    alias Angle = Typedef!double;
    Angle x = 0.5;
    auto y1 = sin(x); // Error.
    auto y2 = sin(cast(TypedefType!Angle)x); // OK.
}

A bit verbose, but it accomplishes what you want and is more DRY and safer than
cast(double)x.

--
September 25, 2014
https://issues.dlang.org/show_bug.cgi?id=12597

--- Comment #12 from bearophile_hugs@eml.cc ---
(In reply to monkeyworks12 from comment #11)
> I think this enhancement request should be closed now that https://github.com/D-Programming-Language/phobos/pull/2116 has been merged. With that PR, your first example now becomes:
> 
> void main() {
>     import std.typecons: Typedef;
>     import std.math: sin;
>     alias Angle = Typedef!double;
>     Angle x = 0.5;
>     auto y1 = sin(x); // Error.
>     auto y2 = sin(cast(TypedefType!Angle)x); // OK.
> }
> 
> A bit verbose, but it accomplishes what you want and is more DRY and safer
> than cast(double)x.

This ER asks for a function like "typedefVal" that's usable like:

auto y2 = x.typedefVal.sin; // OK.

Casts are unsafe, their usage should be minimized in D code. So this ER is still valid.

--
September 26, 2014
https://issues.dlang.org/show_bug.cgi?id=12597

--- Comment #13 from monkeyworks12@hotmail.com ---
(In reply to bearophile_hugs from comment #12)
> (In reply to monkeyworks12 from comment #11)
> > I think this enhancement request should be closed now that https://github.com/D-Programming-Language/phobos/pull/2116 has been merged. With that PR, your first example now becomes:
> > 
> > void main() {
> >     import std.typecons: Typedef;
> >     import std.math: sin;
> >     alias Angle = Typedef!double;
> >     Angle x = 0.5;
> >     auto y1 = sin(x); // Error.
> >     auto y2 = sin(cast(TypedefType!Angle)x); // OK.
> > }
> > 
> > A bit verbose, but it accomplishes what you want and is more DRY and safer
> > than cast(double)x.
> 
> This ER asks for a function like "typedefVal" that's usable like:
> 
> auto y2 = x.typedefVal.sin; // OK.
> 
> Casts are unsafe, their usage should be minimized in D code. So this ER is still valid.

But casting to TypedefType!(typeof(x)) is always safe, 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;
}

--
September 26, 2014
https://issues.dlang.org/show_bug.cgi?id=12597

--- Comment #14 from bearophile_hugs@eml.cc ---
(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.

--
September 26, 2014
https://issues.dlang.org/show_bug.cgi?id=12597

--- Comment #15 from bearophile_hugs@eml.cc ---
(In reply to bearophile_hugs from comment #14)

> > auto typedefVal(T)(T val)
> > {
> >     return cast(TypedefType!T)val;
> > }
> 
> Yes, this ER asks for such safe function in Phobos.

But it's better to add a template constraint to that T to be sure it's a Typedef.

--
March 13, 2018
https://issues.dlang.org/show_bug.cgi?id=12597

Bastiaan Veelo <Bastiaan@Veelo.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Bastiaan@Veelo.net

--- Comment #16 from Bastiaan Veelo <Bastiaan@Veelo.net> ---
(In reply to bearophile_hugs from comment #15)
> (In reply to bearophile_hugs from comment #14)
> 
> > > auto typedefVal(T)(T val)
> > > {
> > >     return cast(TypedefType!T)val;
> > > }
> > 
> > Yes, this ER asks for such safe function in Phobos.
> 
> But it's better to add a template constraint to that T to be sure it's a Typedef.

No need:

/// Instantiating with a non-Typedef will return that type
static assert(is(TypedefType!int == int));

--
April 03, 2022
https://issues.dlang.org/show_bug.cgi?id=12597

tyckesak <josipp@live.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |josipp@live.de

--- Comment #17 from tyckesak <josipp@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.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=12597

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P4

--
1 2
Next ›   Last »