UFCS and error messages

Andrea Fontana nospam at example.com
Thu Oct 31 03:58:18 PDT 2013


Check this simple code:

import std.stdio;
import std.conv;

bool is_zero(T)(T i) { return to!int(i) == 0; }

void main() { "0".is_zero.writeln; }

This code print "true" of course.

If you replace "to!int(i) == 0" with "i == 0" compiler gives this 
error:

"Error: no property 'is_zero' for type 'string'"

But:

is_zero("0")

instead gives this:

Error: incompatible types for ((i) == (0)): 'string' and 'int'

Shoudn't "0".is_zero give this error too?


More information about the Digitalmars-d-learn mailing list