Alias parameter predicates considered harmful?
Vladimir Panteleev
thecybershadow.lists at gmail.com
Mon Mar 22 01:55:29 UTC 2021
On Saturday, 20 March 2021 at 01:03:39 UTC, Paul Backus wrote:
> Here's an idiom I've found useful in situations like this:
>
> /// Pass struct members as arguments to a function
> alias apply(alias fun) = args => fun(args.tupleof);
Thank you. This is indeed a good trick.
> auto fun() @nogc
> {
> int toAdd = 1;
> return iota(10)
> .zip(repeat(toAdd))
> .map!(apply!((n, toAdd) => n + toAdd));
> }
Using `repeat` to pass data to range predicates feels dirty and
wrong, though. :)
More information about the Digitalmars-d
mailing list