Using map result type
Meta
jared771 at gmail.com
Wed Dec 11 20:16:16 UTC 2019
On Wednesday, 11 December 2019 at 20:08:37 UTC, Meta wrote:
> import std.algorithm;
> import std.range;
>
> void mapAccepter(E)(InputRange!E r)
> {
> import std.array: array;
> import std.stdio: writeln;
>
> auto collected = r.array;
> writeln(collected);
> }
>
> void main()
> {
> int[] nums = [1, 2, 3];
> auto evenness = inputRangeObject(map!(n => n % 2 ==
> 0)(nums));
> mapAccepter(evenness);
> }
I guess I should mention, that if you are expecting a range of
booleans, you can of course write mapAccepter as a non-templated
function:
void mapAccepter(InputRange!bool r);
But if you want to support any type of input range, the function
needs to at least be templated on the element type of the range.
More information about the Digitalmars-d-learn
mailing list