The OpenD Programming Language

byValue

Returns a forward range which will iterate over the values of the associative array. The values are returned by reference.

If structural changes are made to the array (removing or adding keys), all ranges previously obtained through this function are invalidated. The following example program will dereference a null pointer:

import std.stdio : writeln;

auto dict = ["k1": 1, "k2": 2];
auto valueRange = dict.byValue;
dict.clear;
writeln(valueRange.front);    // Segmentation fault
  1. auto byValue(T aa)
  2. auto byValue(T* aa)
    pure nothrow @nogc
    byValue
    (
    T : V[K]
    K
    V
    )
    (
    T* aa
    )

Parameters

aa T*

The associative array.

Return Value

Type: auto

A forward range referencing the values of the associative array.

Examples

auto dict = ["k1": 1, "k2": 2];
int sum;
foreach (v; dict.byValue)
    sum += v;

assert(sum == 3);

Meta