DIPX: Enum Literals / Implicit Selector Expression

12345swordy alexanderheistermann at gmail.com
Fri Jul 8 13:35:12 UTC 2022


On Thursday, 7 July 2022 at 15:51:08 UTC, Nick Treleaven wrote:
> On Thursday, 7 July 2022 at 15:19:59 UTC, Alexandru Ermicioi 
> wrote:
>> On Thursday, 7 July 2022 at 13:59:17 UTC, 12345swordy wrote:
>>> Side note: Does D really needs function overloading? You can 
>>> achieve the same effect by using meta-programming.
>>>
>>> - Alex
>>
>> Just wondering, how do you achieve it using meta-programming?
>
> For non-virtual functions, just use a template function:
>
> ```d
> auto f(T)(T v)
> {
> 	static if (is(T : int))
> 		// insert code for f(int) overload
> 	else
> 		...
> }
> ```
>
> It doesn't work for virtual functions as they can't be 
> templates.

This can be solved by having a top type named "Any" to indicate 
that it can be any type for virtual functions.

-Alex


More information about the Digitalmars-d mailing list