DIPX: Enum Literals / Implicit Selector Expression

Nick Treleaven nick at geany.org
Thu Jul 7 15:51:08 UTC 2022


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.


More information about the Digitalmars-d mailing list