#include <algorithm>
#include <iostream>
#include <array>
struct range
{
struct const_iterator
{
const_iterator()
: r(0), i(0) { }
const_iterator(range const * range, int index)
:r(range), i(index) { }
bool operator==(const const_iterator& rhs) const { return *r == *(rhs.r) && i == rhs.i; }
bool operator!=(const const_iterator& rhs) const { return !(*this == rhs); }
int operator*() const { return r->start + i; }
const_iterator& operator++() { ++i; return *this; }
private:
range const * r;
int i;
};
range(int astart, int astop)
: start(astart), count(astop-astart) { if (count < 0) count = 0; }
range(int cnt)
: start(0), count(cnt) { }
bool operator==(const range& r) const { return start == r.start && count == r.count; }
bool operator!=(const range& r) const { return !(*this == r); }
const_iterator begin() const { return const_iterator(this, 0); }
const_iterator end() const { return const_iterator(this, count); }
private:
int start;
int count;
};
int main()
{
using a4M = std::array<uint32_t, 10*10>;
using AxG = std::vector<a4M>;
AxG memory;
uint32_t counter = 0;
for(auto x: range(10)) {
a4M block;
for(auto& elem: block) {
elem = ++counter;
}
memory.push_back(block);
}
for(auto& block: memory) {
for(auto& elem: block) {
std::cout << int(elem) << ' ';
}
std::cout << std::endl;
}
}
CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPGFycmF5PgoKCiAgICBzdHJ1Y3QgcmFuZ2UKICAgIHsKICAgICAgICBzdHJ1Y3QgY29uc3RfaXRlcmF0b3IKICAgICAgICB7CiAgICAgICAgICAgIGNvbnN0X2l0ZXJhdG9yKCkKICAgICAgICAgICAgICAgIDogcigwKSwgaSgwKSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB7IH0KICAgICAgICAgICAgY29uc3RfaXRlcmF0b3IocmFuZ2UgY29uc3QgKiByYW5nZSwgaW50IGluZGV4KQogICAgICAgICAgICAgICAgOnIocmFuZ2UpLCBpKGluZGV4KSAgICAgICAgICAgICAgICAgICAgICAgICAgIHsgfQogICAgICAgICAgICBib29sIG9wZXJhdG9yPT0oY29uc3QgY29uc3RfaXRlcmF0b3ImIHJocykgY29uc3QgIHsgIHJldHVybiAqciA9PSAqKHJocy5yKSAmJiBpID09IHJocy5pOyB9CiAgICAgICAgICAgIGJvb2wgb3BlcmF0b3IhPShjb25zdCBjb25zdF9pdGVyYXRvciYgcmhzKSBjb25zdCAgeyAgcmV0dXJuICEoKnRoaXMgPT0gcmhzKTsgICAgICAgICAgICAgIH0KICAgICAgICAgICAgaW50ICBvcGVyYXRvciooKSAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0ICB7ICByZXR1cm4gci0+c3RhcnQgKyBpOyAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICBjb25zdF9pdGVyYXRvciYgIG9wZXJhdG9yKysoKSAgICAgICAgICAgICAgICAgICAgIHsgICsraTsgcmV0dXJuICp0aGlzOyAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgcHJpdmF0ZToKICAgICAgICAgICAgcmFuZ2UgY29uc3QgKiByOwogICAgICAgICAgICBpbnQgaTsKICAgICAgICB9OwoKICAgICAgICByYW5nZShpbnQgYXN0YXJ0LCBpbnQgYXN0b3ApCiAgICAgICAgICAgIDogc3RhcnQoYXN0YXJ0KSwgY291bnQoYXN0b3AtYXN0YXJ0KSAgeyBpZiAoY291bnQgPCAwKSBjb3VudCA9IDA7ICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICByYW5nZShpbnQgY250KQogICAgICAgICAgICA6IHN0YXJ0KDApLCAgICAgIGNvdW50KGNudCkgICAgICAgICAgIHsgfQogICAgICAgIGJvb2wgb3BlcmF0b3I9PShjb25zdCByYW5nZSYgcikgICAgY29uc3QgIHsgIHJldHVybiBzdGFydCA9PSByLnN0YXJ0ICYmIGNvdW50ID09IHIuY291bnQ7ICB9CiAgICAgICAgYm9vbCBvcGVyYXRvciE9KGNvbnN0IHJhbmdlJiByKSAgICBjb25zdCAgeyAgcmV0dXJuICEoKnRoaXMgPT0gcik7ICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICBjb25zdF9pdGVyYXRvciBiZWdpbigpICAgICAgICAgICAgIGNvbnN0ICB7ICByZXR1cm4gY29uc3RfaXRlcmF0b3IodGhpcywgMCk7ICAgICAgICAgICAgICAgfQogICAgICAgIGNvbnN0X2l0ZXJhdG9yIGVuZCgpICAgICAgICAgICAgICAgY29uc3QgIHsgIHJldHVybiBjb25zdF9pdGVyYXRvcih0aGlzLCBjb3VudCk7ICAgICAgICAgICB9CgogICAgcHJpdmF0ZToKICAgICAgICBpbnQgc3RhcnQ7CiAgICAgICAgaW50IGNvdW50OwogICAgfTsKCgppbnQgbWFpbigpCnsKICAgIHVzaW5nIGE0TSA9IHN0ZDo6YXJyYXk8dWludDMyX3QsIDEwKjEwPjsKICAgIHVzaW5nIEF4RyA9IHN0ZDo6dmVjdG9yPGE0TT47CgogICAgQXhHIG1lbW9yeTsKICAgIHVpbnQzMl90IGNvdW50ZXIgPSAwOwogICAgZm9yKGF1dG8geDogcmFuZ2UoMTApKSB7CiAgICAgICBhNE0gYmxvY2s7CiAgICAgICBmb3IoYXV0byYgZWxlbTogYmxvY2spIHsKICAgICAgICAgICBlbGVtID0gKytjb3VudGVyOwogICAgICAgfQogICAgICAgbWVtb3J5LnB1c2hfYmFjayhibG9jayk7CiAgICB9CgogICAgZm9yKGF1dG8mIGJsb2NrOiBtZW1vcnkpIHsKICAgICAgICBmb3IoYXV0byYgZWxlbTogYmxvY2spIHsKICAgICAgICAgICAgc3RkOjpjb3V0IDw8IGludChlbGVtKSA8PCAnICc7CiAgICAgICAgfQogICAgICAgIHN0ZDo6Y291dCA8PCBzdGQ6OmVuZGw7CiAgICB9Cn0K