On Monday, 1 November 2021 at 21:32:21 UTC, Ali Çehreli wrote:
Joking aside, I liked the nested struct and its opAssign to mimic internal `arr.length = 42` syntax. (I know it involves a potentially expensive delegate but still...)

The nested struct is not needed. UFCS works for setters, too:

```D
void assumedLength(S)(ref S slice, size_t length) {
    if(slice.length >= length)
        slice.length = length;
    else
        assert(false, "Let's not corrupt memory today.");
}

void main() {
  auto arr = [ 1, 2, 3 ];
  arr.assumedLength = 2;
  writeln(arr);
}
```

Reply via email to