byCategory - multiple declarations

Function byCategory

Given a range of values and a range of categories, separates values by category. This function also guarantees that the order within each category will be maintained.

ElementType!V[][ElementType!C] byCategory(V, C) (
  V values,
  C categories
)
if (isInputRange!V && isInputRange!C && !is(ElementType!C == bool));

Note

While the general convention of this library is to try to avoid heap allocations whenever possible so that multithreaded code scales well and false pointers aren't an issue, this function allocates like crazy because there's basically no other way to implement it. Don't use it in performance-critical multithreaded code.

Examples

uint[] values = [1,2,3,4,5,6,7,8];
bool[] categories = [false, false, false, false, true, true, true, true];
auto separated = byCategory(values, categories);
auto tResult = studentsTTest(separated.values);

Function byCategory

Special case implementation for when ElementType!C is boolean.

ElementType!V[][2] byCategory(V, C) (
  V values,
  C categories
)
if (isInputRange!V && isInputRange!C && is(ElementType!C == bool));