On 11/06/2013 03:04 AM, bearophile wrote:
import std.typecons: Typedef;
alias Foo = Typedef!double;
void main() {
auto a1 = Foo(1);
pragma(msg, typeof(a1));
auto a2 = 1.Foo;
pragma(msg, typeof(a2));
auto a3 = Foo(-1);
pragma(msg, typeof(a3));
auto a4 = -1.Foo;
pragma(msg, typeof(a4));
}
It prints:
Typedef!(double, nan)
Typedef!(double, nan)
Typedef!(double, nan)
double
Is this expected/acceptable/good?
Bye,
bearophile
I would be very surprised if unary "-" produced a different type from
the operand:
import std.typecons: Typedef;
alias Foo = Typedef!double;
void main() {
auto a = 1.Foo;
auto b = -a;
static assert (is (typeof(a) == typeof(b))); // FAILS!
}
After all, we are used to hidden bugs based on that expectation: ;)
void main()
{
uint a = 1;
auto b = -a;
assert(b == uint.max); // WT?
static assert(is (typeof(b) == uint)); // <-- the reason
}
Seriously though, yeah, unary "-" must return Typedef!(double, nan).
Ali