Skip to content

Instantly share code, notes, and snippets.

@daverigby
Last active November 22, 2018 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daverigby/24ff11a4334c42b01d076926f4e7a2f4 to your computer and use it in GitHub Desktop.
Save daverigby/24ff11a4334c42b01d076926f4e7a2f4 to your computer and use it in GitHub Desktop.
Checkpoint iterator ideal API - not yet working...
#include <iostream>
#include <list>
#include <vector>
using Container = std::list<int>;
void print(const Container& v) {
std::cout << "[";
for (auto& e : v) {
std::cout << e << " ";
}
std::cout << "]\n";
}
#if 0
class magic_iterator {
public:
auto operator++() {
--reverse_iterator;
}
bool operator==(magic_iterator) {
}
private:
Container::reverse_iterator rit;
};
#endif
auto make_cursor(Container& v) {
// XXX do somthing with a new iterator
return v.begin();
}
auto checkpoint_end(Container& v) {
return v.end();
}
int main() {
Container v;
// Initially populate with 2 elements
v.push_back(1);
v.push_back(2);
v.push_back(3);
print(v);
// get a "checkpoint" / "off_by_one" iterator
auto cursor = make_cursor(v);
for (; cursor != checkpoint_end(v); cursor++) {
// consume cursor...
std::cout << *cursor << " ";
}
v.push_back(4);
v.push_back(5);
for (; cursor != checkpoint_end(v); cursor++) {
// consume cursor...
std::cout << *cursor;
}
std::cout << "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment