+ Blk *blk2; // Dynamically allocated array of the blocks
+
+ static Blk x; // trash that [] can return for out-of-range requests
+
+ void dump() const {
+ std::cout << "Dumping NumberlikeArray @ " << (void *)(this) << '\n';
+ std::cout << "Length " << (len) << ", capacity " << (cap) << '\n';
+ for (unsigned int i = 0; i < len; i++) {
+ std::cout << "Block " << i << ":" << blk2[i] << '\n';
+ }
+ }
+
+ struct BoundsCheckingBlk {
+ const NumberlikeArray *na;
+ BoundsCheckingBlk(NumberlikeArray *na) {
+ this->na = na;
+ }
+ Blk & operator [](Index index) const {
+ if (index >= na->len) {
+ std::cout << "== Out-of-bounds access to block " << index << ". Affected NumberlikeArray: ==\n";
+ na->dump();
+ std::cout << "== End of dump. ==" << std::endl;
+ return x;
+ } else
+ return na->blk2[index];
+ } // dangerous because it allows ``always writable'', but OK for now
+ /*const Blk & operator [](Index index) const {
+ if (index >= na->len)
+ std::cout << "OUT OF BOUNDS! Length " << (na->len) << ", accessed " << index << std::endl;
+ else
+ return na->blk[index];
+ }*/
+ /*operator Blk * () {
+ return na->blk2;
+ }*/
+ };
+
+ BoundsCheckingBlk blk;