C++ still doesn't have good loop syntax

Forum User forumuser at example.com
Tue Aug 11 20:57:58 UTC 2026


On Monday, 10 August 2026 at 00:08:04 UTC, Walter Bright wrote:
> 
> [...] Nobody says value-key. It's always key-value!
>

Except in the case of opIndexAssign:

struct S (T)
{
    size_t siz;
    T [] t;

    @disable this ();

    this (size_t siz)
    {
       t = new T [siz];
       this.siz = siz;
    }

    auto opIndexAssign (size_t i, T v)
    {
       return t [i] = v;
    }
}

void main ()
{
    auto s = S!double (4);
    foreach (i; 0 .. s.siz)
       s [i] = 1000;
}

core.exception.ArrayIndexError at soia.d(16): index [1000] is out of 
bounds for array of length 4



More information about the Digitalmars-d mailing list