I'd like to pass a single lvalue to a function which expects a pair of iterators, and for it to act as if I'd passed a pair of iterators to a range containing just this value.
My approach is as follows:
#include <iostream>
#include <vector>
template<typename Iter>
void iterate_over(Iter begin, Iter end){
for(auto i = begin; i != end; ++i){
std::cout << *i << std::endl;
}
}
int main(){
std::vector<int> a{1,2,3,4};
iterate_over(a.cbegin(), a.cend());
int b = 5;
iterate_over(&b, std::next(&b));
}
This appears to work correctly in g++5.2, but I'm wondering if this is actually defined behaviour and if there are any potential issues?