Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
util::BeginEndWrapper< Iterator > Class Template Reference

#include <iterators.h>

Public Types

using const_iterator = Iterator
using value_type = typename std::iterator_traits<Iterator>::value_type

Public Member Functions

 BeginEndWrapper ()=default
 If Iterator is default-constructible, an empty range.
 BeginEndWrapper (Iterator begin, Iterator end)
Iterator begin () const
Iterator end () const
size_t size () const
 Available only if Iterator is a random access iterator.
bool empty () const

Detailed Description

template<typename Iterator>
class util::BeginEndWrapper< Iterator >

This is useful for wrapping iterators of a class that support many different iterations. For instance, on a Graph class, one can write:

BeginEndWrapper<OutgoingArcIterator> Graph::OutgoingArcs(NodeInde node) const { return BeginEndWrapper( OutgoingArcIterator(this, node, /*at_end=‍/false), OutgoingArcIterator(this, node, /*at_end=‍/true)); }

And a client will use it like this:

for (const ArcIndex arc : graph.OutgoingArcs(node)) { ... }

Note
BeginEndWrapper is conceptually a borrowed range as per the C++ standard (std::ranges::borrowed_range): "The concept borrowed_range defines the requirements of a range such that a function can take it by value and return iterators obtained from it without danger of dangling". We cannot static_assert this property though as std::ranges is prohibited in google3.

Definition at line 48 of file iterators.h.

Member Typedef Documentation

◆ const_iterator

template<typename Iterator>
using util::BeginEndWrapper< Iterator >::const_iterator = Iterator

Definition at line 50 of file iterators.h.

◆ value_type

template<typename Iterator>
using util::BeginEndWrapper< Iterator >::value_type = typename std::iterator_traits<Iterator>::value_type

Definition at line 51 of file iterators.h.

Constructor & Destructor Documentation

◆ BeginEndWrapper() [1/2]

template<typename Iterator>
util::BeginEndWrapper< Iterator >::BeginEndWrapper ( )
default

If Iterator is default-constructible, an empty range.

◆ BeginEndWrapper() [2/2]

template<typename Iterator>
util::BeginEndWrapper< Iterator >::BeginEndWrapper ( Iterator begin,
Iterator end )
inline

Definition at line 56 of file iterators.h.

Member Function Documentation

◆ begin()

template<typename Iterator>
Iterator util::BeginEndWrapper< Iterator >::begin ( ) const
inline

Definition at line 58 of file iterators.h.

◆ empty()

template<typename Iterator>
bool util::BeginEndWrapper< Iterator >::empty ( ) const
inline

Definition at line 64 of file iterators.h.

◆ end()

template<typename Iterator>
Iterator util::BeginEndWrapper< Iterator >::end ( ) const
inline

Definition at line 59 of file iterators.h.

◆ size()

template<typename Iterator>
size_t util::BeginEndWrapper< Iterator >::size ( ) const
inline

Available only if Iterator is a random access iterator.

Definition at line 62 of file iterators.h.


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