Reputation: 13713
In C++, is there a struct
(or class) defined representing a pair of iterators -- one the beginning and one the ending iterator? What's best practice to represent that? std::pair
? I know that I can easily build that myself, but I would like to follow common practice.
I search for the following:
template<class It>
struct XXX {
private:
It b;
It e;
public:
It begin () const { return b; }
It end () const { return e; }
// ...
};
Upvotes: 5
Views: 1440
Reputation: 94329
If it's a pair of two arbitrary iterators it's just that - a pair of iterators.
If it happens to be a pair of iterators for which certain assumptions hold, such as "They point into the same container", I'd call it "Range" since that's what it's called throughout the documentation of the standard template library:
The SGI Introduction to the Standard Template Library writes Find takes three arguments: two iterators that define a range, and a value to search for in that range. It examines each iterator in the range [first, last), proceeding from the beginning to the end, and stops either when it finds an iterator that points to value or when it reaches the end of the range.
.
cplusplus.com writes (yeah, I know the credibility of that site is rather poor, but anyway): A range is any sequence of objects that can be accessed through iterators or pointers, such as an array or an instance of some of the STL containers.
The Working Draft for the C++ Standard writes in 24.2.1 paragraph 7: A range is a pair of iterators that designate the beginning and end of the computation. A range [i,i) is an
empty range; in general, a range [i,j) refers to the elements in the data structure starting with the element
pointed to by i and up to but not including the element pointed to by j
Upvotes: 5
Reputation: 40613
Have a look at Boost.Range, in particular boost::iterator_range.
Upvotes: 4