I also agree. But the array class was one of the first classes that I wrote back in the last millenium, and I wasn’t quite such a C++ ninja back then. If I’d written it now, it’d certainly be very different, but to change it now would break a lot of dependant code.
The mistake I made was in saying that it’s ok to call operator with an out-of-bounds array index, which means that it can’t return a reference, because for invalid indexes, it’ll need to return a new default object. In my own code, I never use any more, I always use .getReference(), and I wish I could make operator work like that without repercussions.
That’s how it used to work, and that was indeed considered best practice until C++11 came along. Nowadays, you’re always supposed to return non-const objects, so that they can have their move operator applied if the type supports that.
