Created
December 19, 2014 07:41
-
-
Save wancw/568f448e9800270fd859 to your computer and use it in GitHub Desktop.
C++ iterator abstraction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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