static map as a type function

Stefan Koch uplink.coder at googlemail.com
Wed Sep 23 13:38:14 UTC 2020


On Wednesday, 23 September 2020 at 13:19:34 UTC, Steven 
Schveighoffer wrote:
> On 9/23/20 8:40 AM, Stefan Koch wrote:
>> On Wednesday, 23 September 2020 at 12:22:49 UTC, Jacob 
>> Carlborg wrote:
>>> On Wednesday, 23 September 2020 at 09:46:54 UTC, Stefan Koch 
>>> wrote:
>>>
>>>> static assert(static_map_tf!sizeOf(Int, Ushort) == [4, 2]);
>>>
>>> Is it possible to use a lambda here?
>>>
>> It should be in theory but I advise against it. Mixing lambdas 
>> and template alias parameters leads to instantiating different 
>> template instances although semantically they're the same.
>
> what about:
>
> static_map_tf!((alias a) => a.sizeof)(...)
>
> This shouldn't be a template.
>
> -Steve

with:
pragma(msg, (static_map_tf!((alias a) => a.sizeof)(Int, Ushort) 
== [4, 2]));
pragma(msg, (static_map_tf!((alias a) => a.sizeof)(Int, Ushort) 
== [4, 2]));

-vtemplates reports:

static_map_tf.d(12): vtemplate: 2 (2 unique) instantiation(s) of 
template `static_map_tf(alias F)(alias_array types...)` found


with

pragma(msg, (static_map_tf!((alias a) => a.sizeof)(Int, Ushort) 
== [4, 2]));
pragma(msg, (static_map_tf!((alias a) => a.sizeof)(Int, Ushort) 
== [4, 2]));
pragma(msg, (static_map_tf!((alias a) => a.sizeof)(Int, Ushort) 
== [4, 2]));

static_map_tf.d(12): vtemplate: 3 (3 unique) instantiation(s) of 
template `static_map_tf(alias F)(alias_array types...)` found


More information about the Digitalmars-d mailing list