Simbody  3.6
SimTK::IteratorRange< Iterator > Class Template Reference

Helper class to use range-based for loops with a pair of iterators. More...

Public Member Functions

 IteratorRange (Iterator first, Iterator last)
 This constructor allows you to iterate over the range [first, last); this means last won't be reached. More...
 
 IteratorRange (const std::pair< Iterator, Iterator > &range)
 
Iterator begin () const
 
Iterator end () const
 

Related Functions

(Note that these are not member functions.)

template<class Iterator >
IteratorRange< Iterator > makeIteratorRange (Iterator first, Iterator last)
 Make an IteratorRange object to be used in a range-based for loop, using two iterators. More...
 
template<class Iterator >
IteratorRange< Iterator > makeIteratorRange (const std::pair< Iterator, Iterator > &range)
 Make an IteratorRange object to be used in a range-based for loop, using an std::pair of iterators. More...
 

Detailed Description

template<class Iterator>
class SimTK::IteratorRange< Iterator >

Helper class to use range-based for loops with a pair of iterators.

This class should only be used when you're sure the iterators are valid. Don't use this class directly; instead, use makeIteratorRange().

Here's an example of using iterators first and last to iterate over the range [first, last) (that is, last won't be reached):

std::vector<int> v {5, 10, 15, 20, 22};
auto first = std::lower_bound(v.begin(), v.end(), 10);
auto last = std::lower_bound(v.begin(), v.end(), 15); // actually points to 20.
for (auto& x : makeIteratorRange(first, last)) {
...
}

You can also use this class with an std::pair of iterators, such as that returned by std::multimap::equal_range(). We assume the first iterator in the pair is the first iterator in the range, and the second iterator in the pair is the last iterator in the range.

std::multimap<std::string, int> map;
...
for (auto& x : makeIteratorRange(map.equal_range("some_key"))) {
...
}

Constructor & Destructor Documentation

◆ IteratorRange() [1/2]

template<class Iterator>
SimTK::IteratorRange< Iterator >::IteratorRange ( Iterator  first,
Iterator  last 
)
inline

This constructor allows you to iterate over the range [first, last); this means last won't be reached.

◆ IteratorRange() [2/2]

template<class Iterator>
SimTK::IteratorRange< Iterator >::IteratorRange ( const std::pair< Iterator, Iterator > &  range)
inlineexplicit

Member Function Documentation

◆ begin()

template<class Iterator>
Iterator SimTK::IteratorRange< Iterator >::begin ( ) const
inline

◆ end()

template<class Iterator>
Iterator SimTK::IteratorRange< Iterator >::end ( ) const
inline

Friends And Related Function Documentation

◆ makeIteratorRange() [1/2]

template<class Iterator >
IteratorRange< Iterator > makeIteratorRange ( Iterator  first,
Iterator  last 
)
related

Make an IteratorRange object to be used in a range-based for loop, using two iterators.

See also
IteratorRange::IteratorRange()

◆ makeIteratorRange() [2/2]

template<class Iterator >
IteratorRange< Iterator > makeIteratorRange ( const std::pair< Iterator, Iterator > &  range)
related

Make an IteratorRange object to be used in a range-based for loop, using an std::pair of iterators.


The documentation for this class was generated from the following file: