W
workusenet1
I have a need for behavior like the chain() function in python's
itertools. It applies a composite pattern to iterators, allowing the
coder to iterate over multiple lists in sequence:
for i in itertools.chain([1, 2], [3, 4]): print i, # prints 1 2 3 4
I looked at boost's iterator library which is like python's itertools
in many respects, but unless I missed something it does not have a
parallel to chain().
What I'm hoping for is something like the following:
vector<int> a, b;
a.push_back(1); a.push_back(2);
b.push_back(3); b.push_back(4);
chain<vector<int>::iterator> ch;
ch.add_range(a.begin(), a.end());
ch.add_range(b.begin(), b.end());
for(chain<vector<int>::iterator>::iterator i = ch.begin(); i !=
ch.end(); ++ch)
{
std::cout << *ch;
}
// above prints 1234
I can probably roll my own, but I wanted to see if someone had already
produced this wheel before I reinvented it.
Thanks!
itertools. It applies a composite pattern to iterators, allowing the
coder to iterate over multiple lists in sequence:
for i in itertools.chain([1, 2], [3, 4]): print i, # prints 1 2 3 4
I looked at boost's iterator library which is like python's itertools
in many respects, but unless I missed something it does not have a
parallel to chain().
What I'm hoping for is something like the following:
vector<int> a, b;
a.push_back(1); a.push_back(2);
b.push_back(3); b.push_back(4);
chain<vector<int>::iterator> ch;
ch.add_range(a.begin(), a.end());
ch.add_range(b.begin(), b.end());
for(chain<vector<int>::iterator>::iterator i = ch.begin(); i !=
ch.end(); ++ch)
{
std::cout << *ch;
}
// above prints 1234
I can probably roll my own, but I wanted to see if someone had already
produced this wheel before I reinvented it.
Thanks!