On type functions
Stefan Koch
uplink.coder at googlemail.com
Sun May 3 11:11:03 UTC 2020
On Sunday, 3 May 2020 at 11:05:13 UTC, Panke wrote:
> On Sunday, 3 May 2020 at 10:52:37 UTC, Stefan Koch wrote:
>>
>> If there are any other open questions about how this is
>> supposed to work I am happy to answer them.
>
> I think type functions are important work.
>
> What operations are available on types? Can I do something like
> this:
>
> ---
> TStruct structFromSpec(string spec)
> {
> TStruct result;
> for (field; parseFields(spec))
> {
> result.addField(field.name, field.type)?
> }
> return result;
> }
> ---
>
> or how is it supposed to look? I'd figure compile times will be
> improved greatly at first and suffer heavily afterwards,
> because everyone will be using this awesome feature to do even
> more at compile time.
>
> Is there any plan to cache the results of type functions? What
> do we need to incorporate into the design to make it cacheable?
>
>
> I am eager to see this in action.
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.
More information about the Digitalmars-d
mailing list