3 ms·
To be fair, you could achieve the same in C++ by only implementing `operator[]() const`.
by deredede 4y ago
To be fair, you could achieve the same in C++ by only implementing `operator[]() const`.
- tialaramex 4y agoHuh. Does that do the same thing? I can't figure it out in my head whether this causes all the correct things to fail and everything else to work.
- deredede 4y agoIf you only implement operator[]() it should do the same thing as only implementing Index in Rust, thanks to implicit cast conversion. Whether it causes "the correct things to fail and everything else to work" is up to interpretation, as this will give you const references to the array values, which is much less idiomatic in C++ than in rust.
- tialaramex 4y agoYeah, I think this probably does what I think ought to happen here, but in the process it probably makes a bunch of reasonable looking C++ not work, and thus would make programmers unhappy which is not a good goal :/
- goalieca 4y agoC++ allows you to override the constness of everything internally by defining a member variable as `mutable`.