Option.opApply

Permit foreach over an option type.

  1. int opApply(int delegate(Some!T) dg)
  2. int opApply(int delegate(const(Some!T)) dg)
    struct Option(T)
    const
    int
    opApply
    (
    int delegate
    (
    const(Some!T)
    )
    dg
    )
    if (
    is(T == class) ||
    isPointer!T
    )
  3. int opApply(int delegate(immutable(Some!T)) dg)

Examples

Option!T value = null;

foreach(someValue; value) {
    // We never enter this loop body.
}

value = new T();

foreach(someValue; value) {
    // We enter this loop body exactly once.
}

Meta