What is the reasoning behind the lack of conversions when passing parameters

FeepingCreature feepingcreature at gmail.com
Tue Feb 6 10:10:32 UTC 2024


On Monday, 5 February 2024 at 09:04:23 UTC, Atila Neves wrote:
> On Saturday, 3 February 2024 at 03:19:00 UTC, Walter Bright 
> wrote:
>> C++ has this, implicit conversion of structs. It looks great 
>> with simple cases. However, as overloading gets more complex, 
>> it becomes a source of mass confusion. I've had many C++ 
>> programmers tell me that nobody actually knows how C++ 
>> overloading works - they just try random things until they get 
>> the result they want. There was a lot of talk in the 90s about 
>> implicit conversion being a mistake, but by then it was too 
>> late and C++ has had to learn to live with it.
>>
>> It's in that class of features that inevitably lead to 
>> incomprehensible code.
>>
>> I tried to make overloading in D much simpler, but it's still 
>> overly complex.
>>
>> Let's not dig that cat out of the pet semetary.
>
> It got bad enough in C++ that the guideline is now to use 
> explicit on single parameter constructors: 
> https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-explicit

I just don't think that "this feature can be abused" is a 
convincing argument. So what? Make it opt-in, mark it as 
dangerous, then when people use it it's on them.

I don't want implicit conversion to always be enabled, I want it 
to be enabled by a keyword or UDA. @implicit or something. Even 
per-parameter would be useful!

Honestly, if you just hardcoded implicit construction for 
`std.sumtype.SumType` I would be quite happy already.


More information about the Digitalmars-d mailing list