I have functions that take in std::vector
iterators, as in
typedef std::vector<Point> Points;
Points ConvexHull(Points::const_iterator first, Points::const_iterator last);
I usually pass the std
iterators to them, but occasionally I need to work with boost
iterators, such as boost::join
's range iterator. How should I change the parametrizations of my functions, ideally without templates, so that they accept both iterators? Moreover, how do I indicate in each type which iterator concepts I need?
I tried looking at the boost::range
documentation but it's overwhelmingly confusing for me and I don't know where to start.
For example, I couldn't find the difference between boost::range_details::any_forward_iterator_interface
and boost::range_details::any_forward_iterator_wrapper
, and whether I should use either of those to specify that I need a forward iterator.
Edit:
If I use boost::any_range
, how can I pass non-const lvalue references?
For example:
template<typename T>
using Range = boost::any_range<T, boost::random_access_traversal_tag,
T, std::ptrdiff_t>;
f(Range<Point> &points); // defined elsewhere
// -------------
vector<Point> vec;
f(vec); // error; cannot bind non-const lvalue reference to unrelated type
size
? It seemssize
is undefined forboost::any_range<Point, boost::bidirectional_traversal_tag, Point, std::ptrdiff_t>
; – Trisect