include limits include iostream include vector include array struct ra

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <limits>
#include <iostream>
#include <vector>
#include <array>
struct range
{
struct itertr
{
itertr(range* range, int index) : r{range}, i{index} {}
bool operator!=(itertr& rhs) { return i != rhs.i; }
int operator*() { return r->start + i; }
auto operator++()->itertr& { ++i; return *this; }
private:
range const * r;
int i;
};
range(int strt, int stp) : start{strt}, count{stp-strt}
{ if (count < 0) count=0; }
range(int cnt) : range{0, cnt} {}
itertr begin() { return {this, 0}; }
itertr end() { return {this, count}; }
private:
int start;
int count;
};
int main() {
for(auto a: range(std::numeric_limits<int>::max())) {
int* x = new int[50000];
std::cout << a << ", ";
}
}