GString.opApply

Enables the use of foreach (size_t, Grapheme; ...) statements.

  1. int opApply(int delegate(Grapheme) @(safe) dg)
  2. int opApply(int delegate(size_t index, Grapheme) @(safe) dg)
    struct GString(CharT)
    int
    opApply
    (
    scope int delegate
    (
    size_t index
    ,
    Grapheme
    )
    @safe
    dg
    )
    if (
    isSomeChar!CharT
    )

Examples

auto t1 = typeof(this)("Test R̆ȧm͆b̪õ");
StringT nakedString;
StringT nakedExpected = "Test Rambo";
size_t isum = 0;
foreach (i, g; t1) {
  isum += i;
  nakedString ~= g[0];
}
assert(isum == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9);
assert(nakedString == nakedExpected);

Meta