Using return type of a predicate function as a template
Edwin van Leeuwen via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Oct 16 01:36:50 PDT 2014
On Thursday, 16 October 2014 at 08:18:02 UTC, Atila Neves wrote:
> This works:
>
> import std.range;
>
> auto groupBy(alias func, R)(R values)
> if (isInputRange!R)
> {
>
> alias K = typeof(func(values.front));
> alias V = ElementType!R[];
> V[K] grouped;
> foreach(value; values) grouped[func(value)] ~= value;
> return grouped;
> }
>
Thank you, that is surprisingly straightforward :)
Edwin
More information about the Digitalmars-d-learn
mailing list