generic + numeric + literals = abomination
so
so at so.do
Sun Mar 28 01:57:58 PDT 2010
Well, i am having hard time explaining, it is not a surprise that you
don't understand.
To make things clearer, lets forget floats for a seconds and change your
code to standard unsigned types.
import std.stdio: writeln;
struct Vector(T) {
this(T m) { mm = m; }
Vector opBinary(string op:"*", T2)(T2 m) if(is(T2 == T)) {
return Vector(mm * m);
}
T mm;
}
void test(T)() {
Vector!T v = Vector!T(5);
Vector!T u = v * 3;
writeln("u: ", u.mm);
}
void main() {
test!ubyte();
test!ushort();
test!uint();
test!ulong();
}
All the tests fail as they should, but check it out, what is wrong with
the templates above?
You can represent 3, and 5 with all these 4 types, but since 3, and 5
actually is an "int" it fails.
Now think about it again with my proposal in mind. Where we add a generic
literal, for this situation,
which covers entire unsigned types, lets pick a generic literal for them,
say... "gu"
void test(T)() {
Vector!T v = Vector!T(5gu);
Vector!T u = v * 3gu;
writeln("u: ", u.mm);
}
Thanks!
On Sun, 28 Mar 2010 12:29:17 +0400, bearophile <bearophileHUGS at lycos.com>
wrote:
> I don't understand your problem/needs, sorry.
>
> Bye,
> bearophile
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
More information about the Digitalmars-d-learn
mailing list