Implicit conversion rules
Marco Leise via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Oct 21 15:49:07 PDT 2015
Am Wed, 21 Oct 2015 12:49:35 -0700
schrieb Ali Çehreli <acehreli at yahoo.com>:
> On 10/21/2015 12:37 PM, Sigg wrote:
>
> > cause at least few more "fun" side effects.
>
> One of those side effects would be function calls binding silently to
> another overload:
>
> void foo(bool){/* ... */}
> void foo(int) {/* ... */}
>
> auto a = 0; // If the type were deduced by the value,
> foo(a); // then this would be a call to foo(bool)...
> // until someone changed the value to 2. :)
>
> Ali
God forbid anyone implement such nonsense into D !
That would be the last thing we need that we cannot rely on
the overload resolution any more. It would be as if making 'a'
const would change the overload resolution when none of the
overloads deal with constness...
import std.format;
import std.stdio;
string foo(bool b) { return format("That's a boolean %s!", b); }
string foo(uint u) { return format("Thats an integral %s!", u); }
void main()
{
int a = 2497420, b = 2497419;
const int c = 2497420, d = 2497419;
writeln(foo(a-b));
writeln(foo(c-d));
writeln("WAT?!");
}
--
Marco
More information about the Digitalmars-d-learn
mailing list