Skip to content

Instantly share code, notes, and snippets.

@wancw
Created December 19, 2014 07:41
Show Gist options
  • Save wancw/568f448e9800270fd859 to your computer and use it in GitHub Desktop.
Save wancw/568f448e9800270fd859 to your computer and use it in GitHub Desktop.
C++ iterator abstraction
#include <vector>
#include <set>
#include <string>
namespace Impl {
typedef std::set<std::string> elem_container;
//typedef std::vector<std::string> elem_container;
typedef elem_container::iterator elem_iterator;
elem_container elems = {
{ "hello" },
{ "world" },
};
elem_iterator foo_start() {
return elems.begin();
};
elem_iterator foo_end() {
return elems.end();
};
}
#include <iostream>
int main() {
Impl::elem_iterator it = Impl::foo_start();
Impl::elem_iterator last = Impl::foo_end();
for (; it != last; ++it) {
std::cout << (*it) << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment