[OT] Move semantics in a nutshell
monkyyy
crazymonkyyy at gmail.com
Sun Nov 9 16:35:13 UTC 2025
On Sunday, 9 November 2025 at 10:19:33 UTC, Timon Gehr wrote:
> On 11/9/25 01:31, monkyyy wrote:
>>
>> When defining an opIndex you got yourself an int, and plenty
>> of context maybe just try solving the problem then and there.
>> I suggest making a singular ugly trade off, instead of the
>> piles and piles of complexity c+ + and rust just inject into
>> the core language and excited to talk about their massive
>> amounts of complexity, slow compiles, and 10000 man hours
>> solutions.
>
> There is no panacea and if you think you found one you are
> probably wrong.
I know yall opinions on actually failsafe code, but you jumped
from "make one ugly tradeoff" to "panacea"
```d
import std;
template innate(T){
T innate;
}
struct myarray(T){
T[] data;
ref T opIndex(int i){
if(i < 0){
return innate!T;
}
if(i >= data.length){
return innate!T;
}
return data[i];
}
//todo more op overloads
alias data this;
}
unittest{
myarray!int foo;
foo[-1000]=3;
foo[1]=6;
foo.map!(a=>assert(0));
foo~=1;
foo~=[2,3];
foreach(e;foo){
e.writeln;
}
}
```
People make stupid problems, an opIndex is a function, I give an
int(and I do mean int, size_t is bad design) and I expect a T
back, I use my huge, massive brain to consider all possible ints
given the context of my data structure.
I dont know how for mere mortals to handle the *manual data flow
analysis* involved with this 2^32 by 2^64 possibility space; but
perhaps you could be convinced it will in fact not crash.
> Look who is relying on language invariants and OS invariants
> now.
The size of ints is hardware level and n^2. Its not the yours or
walters or even c's. Maybe it was boole's maths.
That would be correct in any statically typed language and Im not
thinking about d's number propitiation thingy at all here.
---
and dont go saying that headers and static types are good ideas
because of invarents; they are at least as old as c
More information about the Digitalmars-d
mailing list