Concepts like c++20 with specialized overload resolution.

ryuukk_ ryuukk.dev at gmail.com
Sat May 27 18:41:47 UTC 2023


On Saturday, 27 May 2023 at 17:49:27 UTC, vushu wrote:
> On Saturday, 27 May 2023 at 16:38:43 UTC, Steven Schveighoffer 
> wrote:
>> On 5/27/23 9:50 AM, vushu wrote:
>>> On Saturday, 27 May 2023 at 13:42:29 UTC, Basile B. wrote:
>>>> [...]
>>> 
>>> Yes I know there is template constraint, but not with 
>>> specialized overloading right?
>>> 
>>> so you need to use static if for checking if it hasmagma.
>>
>> What is missing is an "else" thing.
>>
>> So you have to repeat the constraint (as a negation) 
>> unfortunately.
>>
>> e.g.:
>>
>> ```d
>> struct LavaMan {
>>   void magma() { writeln(" LavaMan is throwing LAVA"); }
>> }
>>
>> struct FakeVulcano {
>>   void try_making_lava() { writeln(" Making fake lava"); }
>> };
>>
>> void make_lava(T)(ref T lava) if (hasMagma!T) {
>>     lava.magma();
>> }
>>
>> void make_lava(T)(ref T lava_thing) if (!hasMagma!T){
>>     lava_thing.try_making_lava();
>> }
>> ```
>>
>> -Steve
>
>
> I see thanks for the example :), I think this probably the 
> closest equivalent i dlang.

I feel like overload in that case make things harder to read

My example has less context switch, and hte logic is correctly 
understandable at first sight

Only one make_lava function


More information about the Digitalmars-d-learn mailing list