TDPL: Operator Overloading

Andrej Mitrovic andrej.mitrovich at test.com
Wed Aug 25 08:17:15 PDT 2010


Interesting. :)

The following seems to work, although I don't know if that's a good idea?:

struct CheckedInt(N) // if(isIntegral!N)
{
    void foo(N n)
    {

    }

    unittest
    {
        CheckedInt ci;
        ci.foo(N.init);
    }
}

unittest
{
    CheckedInt!int ci1;
    CheckedInt!uint ci2;
    CheckedInt!string ci3;
}

void main() { }

Steven Schveighoffer Wrote:

>  I've found the only limit  
> here is generating data -- the literals have to match the N type.   
> CheckedInt only instantiates if N is integral, but if that constraint  
> wasn't there, then CheckedInt!string wouldn't compile because the unit  
> test can't convert the literal 1 to a string.
> 
> -Steve



More information about the Digitalmars-d-learn mailing list