DIPX: Enum Literals / Implicit Selector Expression
Paul Backus
snarwin at gmail.com
Fri Jul 8 14:11:08 UTC 2022
On Friday, 8 July 2022 at 13:35:12 UTC, 12345swordy wrote:
> On Thursday, 7 July 2022 at 15:51:08 UTC, Nick Treleaven wrote:
>> 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.
Actually, you can already do this with variadic functions and
`TypeInfo`. Take a look at the third example:
https://dlang.org/spec/function.html#d_style_variadic_functions
More information about the Digitalmars-d
mailing list