Add support implicit conversion between types

Benjamin Thaut code at benjamin-thaut.de
Fri Sep 6 06:15:21 PDT 2013


Am 06.09.2013 15:01, schrieb Dicebot:
> On Friday, 6 September 2013 at 11:32:11 UTC, Benjamin Thaut wrote:
>> Its only a source of troubles in C++ because it is the default
>> behavior. But if you design a library it can make the usage of your
>> api easier and also you have a few more options to stay backwards
>> compatible with your old api.
>
> Probably. But what is the gain? `foo(Foo(5))` looks better than `foo(5)`
> to me in every possible way.
>
> For example, use case that justifies operator overloading (despite the
> danger) in my eyes is ability to replace built-in types with custom
> ones. What is the similar rationale for implicit conversion?

Try implementing a custom string class in D that does not depend on the 
GC and you will know. Your code will be littered with explict 
constructions of strings, which makes it look totally ugly.


More information about the Digitalmars-d mailing list