On type functions
Stefan Koch
uplink.coder at googlemail.com
Sun May 3 11:23:42 UTC 2020
On Sunday, 3 May 2020 at 11:19:23 UTC, Panke wrote:
> On Sunday, 3 May 2020 at 11:11:03 UTC, Stefan Koch wrote:
>>
>> struct from spec is exactly one of the things that will not be
>> possible without wrapping it in a template.
>>
>> template structFromString(string spec)
>> {
>> alias structFromStringTypeFn(string spec)
>> {
>> ...
>> }
>> alias = structFromString = structFromStringTypeFn!(spec);
>> }
>> that looks a bit strange but it allows me to not have to worry
>> about certain constraints that I would otherwise have to worry
>> about.
>
> I have no problem with wrapping it in a template, but want to
> know what can be done inside of structFromStringTypeFn?
You can not create ast-fragments or anything like that but you
can create a string
which when mixed in within the scope of the wrapping template
creates the type you want.
so structFromStringTypeFn would return a string rather than a
type.
The only special thing in a type function is that you can use the
usual `__traits` and tupleof, on the type parameter.
The rest is just like a regular function at ctfe.
More information about the Digitalmars-d
mailing list