Created
May 5, 2019 17:51
-
-
Save AndrewRademacher/c3af049e0cf041127d5cd44c2b18d0e9 to your computer and use it in GitHub Desktop.
testing for proximity to end of iterator in all cases except input iterator.
This file contains 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 <string> | |
#include <iostream> | |
#include <vector> | |
#include <array> | |
#include <set> | |
#include <unordered_set> | |
template<typename T> | |
void printElems(T elems) { | |
std::cout << "[ "; | |
for (auto itr = elems.begin(); itr != elems.end(); ++itr) { | |
std::cout << *itr; | |
// test proximity | |
auto next = itr; | |
++next; | |
if (next != elems.end()) std::cout << ", "; | |
} | |
std::cout << " ]\n"; | |
} | |
int main() { | |
std::vector<uint64_t> vec{1, 2, 3, 4, 5, 6}; | |
printElems(vec); | |
std::array<uint64_t, 5> ary{1, 2, 3, 4, 5}; | |
printElems(ary); | |
std::set<uint64_t> set{1, 2, 3, 4}; | |
printElems(set); | |
std::set<uint64_t> uset{1, 2, 3, 4}; | |
printElems(uset); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: