template alias that includes a parameter
Timoses
timosesu at gmail.com
Sun Jul 1 09:46:55 UTC 2018
On Sunday, 1 July 2018 at 01:48:15 UTC, Simen Kjærås wrote:
>
> I'd send you straight to std.meta.ApplyLeft, but it seems to do
> the wrong thing here, in that it doesn't handle IFTI. This
> thing does:
>
> void fooImpl(int n, T)(const T line) { }
>
> unittest {
> alias fun = applyLeft!(fooImpl, 3);
> fun(`aaa`);
> applyLeft!(fooImpl, 3)(`aaa`);
> }
>
> template applyLeft(alias Fn, T...) {
> auto applyLeft(U...)(U args) {
> return Fn!T(args);
> }
> }
Would be nice if std.meta.ApplyLeft did the job here.. Is there
no way of achieving that?
It's current implementation looks like this:
template ApplyLeft(alias Template, args...)
{
alias ApplyLeft(right...) = SmartAlias!(Template!(args,
right));
}
private template SmartAlias(T...)
{
static if (T.length == 1)
{
alias SmartAlias = Alias!T;
}
else
{
alias SmartAlias = AliasSeq!T;
}
}
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 : /.
[1]: https://dlang.org/spec/traits.html
[2]: https://dlang.org/phobos/std_traits.html
More information about the Digitalmars-d-learn
mailing list