nested function overloading

Chris Katko ckatko at gmail.com
Fri Jun 24 01:01:52 UTC 2022


On Wednesday, 22 June 2022 at 12:42:48 UTC, Steven Schveighoffer 
wrote:
> On 6/22/22 2:05 AM, monkyyy wrote:
>> On Monday, 20 June 2022 at 13:20:51 UTC, Steven Schveighoffer 
>> wrote:
>>> And you can also use an inner struct to define overloaded 
>>> functions.
>> 
>> I believe templates make a better bandaid
>> ```d
>> void main(){
>>      template bar(){
>>          void bar_(int){}
>>          void bar_(float){}
>>          alias bar=bar_;
>>      }
>>      bar(1);
>>      bar(3.14);
>> }
>> ```
>
> Wow, I never thought of that, it's a great idea! You don't even 
> need to use the alias.
>
> ```d
> void main(){
>     template bar(){
>         void bar(int){}
>         void bar(float){}
>     }
>     bar(1);
>     bar(3.14);
> }
> ```
>
> -Steve

Wow! That's great! Another trick to add to my toolbox.


More information about the Digitalmars-d-learn mailing list