First life-signs of type functions
Stefan Koch
uplink.coder at googlemail.com
Thu May 14 08:09:14 UTC 2020
On Wednesday, 13 May 2020 at 19:22:36 UTC, Nick Treleaven wrote:
> On Sunday, 10 May 2020 at 08:39:42 UTC, Nick Treleaven wrote:
>> bool anySatisfy(alias Tem, alias[] S)
>> {
>> bool found;
>> alias E;
>> while (S.length)
>> {
>> E = S[0];
>> if (Tem!E)
>> return true;
>> S = S[1..$];
>> }
>> return false;
>> }
>
> I realized after posting that Tem!E can't work, because the
> type function must be compiled before evaluating E. Tem!E would
> be a constant expression, if it even compiles (e.g. passing E
> as a template alias parameter, not passing the value of E).
>
> So as Stefan wrote, type functions are like CTFE functions
> (maybe a superset?).
Well E is defined at interpretation time.
So I _could_ deferr the template instance until the value of E is
known.
But the whole purpose of type functions is to discourage the use
of templates in cases in which they are not needed.
In cases where a template is needed type functions will be of
little use.
(you can possibly use them to remove internal instances).
More information about the Digitalmars-d
mailing list