The cast(signed), cast(unsigned) feature proposal
Timothee Cour
thelastmammoth at gmail.com
Fri Jun 7 18:26:04 PDT 2013
I'm against it since we can do it better in library with same efficiency
and better UFCS syntax: see
https://github.com/timotheecour/dtools/blob/master/dtools/util/cast_funs.d
to test it, nothing to install, just type: rdmd --main -unittest
dtools/all.d
here's the unittest:
----
version(unittest){
import std.stdio;
int foo(int x){
return x;
}
}
unittest{
double c;
// auto b1=cast(int)c.foo;//means cast(int)(c.foo), so would be CT error
auto b2=(cast(int)c).foo;//verbose syntax: 2 nested parenthesis
auto b3=c.Cast!int.foo;//simpler syntax
int a=1;
auto b=(a+a).Cast!double;
static assert(is(typeof(b)==double));
static assert(is(typeof(a.Cast!Immutable)==immutable(int)));
static assert(is(typeof(a.Cast!Const)==const(int)));
static assert(is(typeof(0U.Cast!Signed)==int));
static assert(is(typeof(a.Cast!Unsigned)==uint));
static assert(is(typeof(a.Cast!Const)==const(int)));
static assert(is(typeof((a+a).Cast!Unsigned)==uint));
}
----
On Fri, Jun 7, 2013 at 5:43 PM, Mrzlga <bulletproofchest at gmail.com> wrote:
> "doing nothing but converting unsigned->signed" is a dubious statement.
>
> They are still screwing with the range, they are not just "doing nothing
> but converting unsigned->signed".
> And 'int' says something about the outcome.
>
> So I am really asking for:
>
> cast(signed int) x; // make them poor programmers write this, lol
>
> That's not what I actually want, but at least it shows: We're making a
> signed conversion, AND we're screwing with the range to make it into an int.
>
> for further thought.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130607/48909119/attachment-0001.html>
More information about the Digitalmars-d
mailing list