DIPX: Enum Literals / Implicit Selector Expression
12345swordy
alexanderheistermann at gmail.com
Fri Jul 8 15:05:59 UTC 2022
On Friday, 8 July 2022 at 14:11:08 UTC, Paul Backus wrote:
> 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
"TypeInfo" isn't a Top type though, nor should it be treated as
one.
More information about the Digitalmars-d
mailing list