16 #ifndef UTIL_GRAPH_ITERATORS_H_ 17 #define UTIL_GRAPH_ITERATORS_H_ 37 template <
typename Iterator>
40 using const_iterator = Iterator;
44 Iterator
begin()
const {
return begin_; }
45 Iterator
end()
const {
return end_; }
50 const Iterator begin_;
57 template <
typename Iterator>
58 inline BeginEndWrapper<Iterator> BeginEndRange(Iterator
begin, Iterator
end) {
59 return BeginEndWrapper<Iterator>(
begin,
end);
61 template <
typename Iterator>
62 inline BeginEndWrapper<Iterator> BeginEndRange(
63 std::pair<Iterator, Iterator> begin_end) {
64 return BeginEndWrapper<Iterator>(begin_end.first, begin_end.second);
70 template <
typename MultiMap>
71 inline BeginEndWrapper<typename MultiMap::iterator> EqualRange(
72 MultiMap& multi_map,
const typename MultiMap::key_type& key) {
73 return BeginEndRange(multi_map.equal_range(key));
75 template <
typename MultiMap>
76 inline BeginEndWrapper<typename MultiMap::const_iterator> EqualRange(
77 const MultiMap& multi_map,
const typename MultiMap::key_type& key) {
78 return BeginEndRange(multi_map.equal_range(key));
85 template <
typename Container>
86 class BeginEndReverseIteratorWrapper {
88 explicit BeginEndReverseIteratorWrapper(
const Container& c) : c_(c) {}
89 typename Container::const_reverse_iterator
begin()
const {
92 typename Container::const_reverse_iterator
end()
const {
return c_.rend(); }
97 template <
typename Container>
98 BeginEndReverseIteratorWrapper<Container> Reverse(
const Container& c) {
99 return BeginEndReverseIteratorWrapper<Container>(c);
103 template <
typename IntegerType>
104 class IntegerRangeIterator
105 :
public std::iterator<std::input_iterator_tag, IntegerType> {
107 explicit IntegerRangeIterator(IntegerType value) : index_(value) {}
108 IntegerRangeIterator(
const IntegerRangeIterator& other)
109 : index_(other.index_) {}
110 IntegerRangeIterator& operator=(
const IntegerRangeIterator& other) {
111 index_ = other.index_;
113 bool operator!=(
const IntegerRangeIterator& other)
const {
116 return index_ < other.index_;
118 bool operator==(
const IntegerRangeIterator& other)
const {
119 return index_ == other.index_;
121 IntegerType operator*()
const {
return index_; }
122 IntegerRangeIterator& operator++() {
126 IntegerRangeIterator operator++(
int) {
127 IntegerRangeIterator previous_position(*
this);
129 return previous_position;
145 template <
typename IntegerType>
146 class IntegerRange :
public BeginEndWrapper<IntegerRangeIterator<IntegerType>> {
148 IntegerRange(IntegerType
begin, IntegerType
end)
150 IntegerRangeIterator<IntegerType>(
begin),
151 IntegerRangeIterator<IntegerType>(
end)) {}
156 struct MutableVectorIteration {
157 explicit MutableVectorIteration(std::vector<T>* v) : v_(v) {}
159 explicit Iterator(
typename std::vector<T>::iterator it) : it_(it) {}
160 T* operator*() {
return &*it_; }
168 typename std::vector<T>::iterator it_;
170 Iterator
begin() {
return Iterator(v_->begin()); }
171 Iterator
end() {
return Iterator(v_->end()); }
174 std::vector<T>*
const v_;
178 #endif // UTIL_GRAPH_ITERATORS_H_ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in c...
Iterator(typename std::vector< T >::iterator it)
BeginEndWrapper(Iterator begin, Iterator end)
bool operator!=(const Iterator &other) const
typename std::iterator_traits< Iterator >::value_type value_type