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

ryuukk_ ryuukk.dev at gmail.com
Wed Feb 7 11:40:18 UTC 2024


On Tuesday, 6 February 2024 at 10:47:15 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
> On 06/02/2024 11:17 PM, Atila Neves wrote:
>> On Tuesday, 6 February 2024 at 10:10:32 UTC, FeepingCreature 
>> wrote:
>>> 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:
>>>>> [...]
>>>>
>>>> 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!
>> 
>> Sure, this would definitely help. I think the lesson learned 
>> there is that implicit conversions *by default* are a bad 
>> idea. I don't even like integer conversions, cast if you want 
>> it.
>> 
>>> Honestly, if you just hardcoded implicit construction for 
>>> `std.sumtype.SumType` I would be quite happy already.
>> 
>> Something I've wanted every time I've used it.
>
> +1 to all of this.
>
> The implicit conversion wouldn't be too hard to implement 
> either.
>
> I actually implemented an implicit conversion today, in 
> preparation of sumtypes!
>
> https://github.com/dlang/dmd/pull/16161
>
> To make the following work:
>
> ```d
> Enum varF2 = identity(:Middle);
>
> Enum identity(Enum e) {
> 	return e;
> }
>
> enum Enum {
> 	Middle
> }
> ```

Simple yet effective, i love it


More information about the Digitalmars-d mailing list