generic + numeric + literals = abomination

so so at
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: ",;

void main() {

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: ",;


On Sun, 28 Mar 2010 12:29:17 +0400, bearophile <bearophileHUGS at>  

> I don't understand your problem/needs, sorry.
> Bye,
> bearophile

Using Opera's revolutionary e-mail client:

More information about the Digitalmars-d-learn mailing list