How to instantiate a map with multiple functions
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Dec 26 16:27:12 PST 2015
On 12/26/2015 11:46 AM, karthikeyan wrote:
> Thanks but the following returns an error for me
>
> import std.algorithm.comparison : equal;
> import std.range : chain;
> int[] arr1 = [ 1, 2, 3, 4 ];
> int[] arr2 = [ 5, 6 ];
> auto dd = map!(z => z * z, c => c * c * c)(chain(arr1, arr2));
> writeln(dd);
>
> Error :
>
> /usr/include/dmd/phobos/std/meta.d(546): Error: template instance
> F!(__lambda2) cannot use local '__lambda2' as parameter to non-global
> template AppliedReturnType(alias f)
That looks like a bug to me. Please report here:
https://issues.dlang.org/
You can call tuple() as a workaround:
import std.stdio;
import std.algorithm;
import std.range;
import std.typecons;
void main() {
int[] arr1 = [ 1, 2, 3, 4 ];
int[] arr2 = [ 5, 6 ];
auto dd = map!(z => tuple(z * z, z * z * z))(chain(arr1, arr2));
writeln(dd);
}
Ali
More information about the Digitalmars-d-learn
mailing list