Further, because of all that, you can create lists out of things that have little to do with arrays or sequences, as long as they have a suitable interface. For example the following, which generates a sequence as demanded (the minimal example might lack a few operators):
Code:
#include <iostream>
#include <list>
class make_sequence
{
int value;
public:
make_sequence(int n): value(n) {}
make_sequence& operator++()
{
++value;
return *this;
}
int operator*() const { return value; }
bool operator!= (make_sequence other) const
{
return value != other.value;
}
};
int main()
{
std::list<int> n(make_sequence(1), make_sequence(10)); //1, 2, 3, 4, 5, 6, 7, 8, 9
for (std::list<int>::iterator it = n.begin(); it != n.end(); ++it) {
std::cout << *it << ' ';
}
}