template alias that includes a parameter
Timoses
timosesu at gmail.com
Sun Jul 1 13:01:20 UTC 2018
On Sunday, 1 July 2018 at 11:55:15 UTC, Simen Kjærås wrote:
> On Sunday, 1 July 2018 at 09:46:55 UTC, Timoses wrote:
>> Would be nice if std.meta.ApplyLeft did the job here.. Is
>> there no way of achieving that?
> [snip]
>> Would have to find a way to determine whether Template would
>> resolve to a function or not. Can't find anything in Traits[1]
>> or std.traits[2]. Template inspection looks rather limited : /.
>
> It is, but for a fairly good reason. This is perfectly valid D:
>
> template foo(int n) {
> static if (n == 0) {
> struct foo {}
> } else static if (n == 1) {
> enum foo = 24;
> } else {
> void foo() {}
> }
> }
>
> Given an uninstantiated foo, you can't know if it'll resolve to
> a function or not, so I guess some version of the template I
> wrote could be added to Phobos as ApplyLeftFn or something.
Aw, okay, then that won't work.
Still, this looks like it should work:
void foo(F, T)(T param) { writeln("Called with type: ",
T.stringof); }
alias tfoo = ApplyLeft!(foo, int);
tfoo!string("hi");
// tfoo("hi"); // Error
More information about the Digitalmars-d-learn
mailing list