On Saturday, 19 November 2016 at 20:08:42 UTC, Marduk wrote:
On Saturday, 19 November 2016 at 11:11:36 UTC, Nordlöw wrote:
On Saturday, 19 November 2016 at 09:38:38 UTC, Marduk wrote:
The difference is that D is more verbose. Am I missing something? Can we have C's behaviour in D?

Something like

auto I(T)(T im)
    if (isNumeric!T)
{
    return complex(0, im);
}

unittest
{
    auto x = 1 + 2.I;
}

Nice. But I am unsure of how to use this. I just pasted the definition of I inside the main function of my program followed by auto x = 1 + 2.I; and the compiler complained with Error: no property 'I' for type 'int'.

Try placing it outside the function. Method call syntax doesn't work with nested functions, see here:

https://dlang.org/spec/function.html#pseudo-member

"The reason why local symbols are not considered by UFCS, is to avoid unexpected name conflicts."

Reply via email to