Audacity 3.2.0
Classes | Public Types | Public Member Functions | List of all members
IteratorRange< Iterator > Struct Template Reference

A convenience for use with range-for. More...

#include <IteratorX.h>

Inheritance diagram for IteratorRange< Iterator >:
[legend]
Collaboration diagram for IteratorRange< Iterator >:
[legend]

Classes

struct  identity
 

Public Types

using iterator = Iterator
 
using reverse_iterator = std::reverse_iterator< Iterator >
 

Public Member Functions

 IteratorRange (const Iterator &a, const Iterator &b)
 
 IteratorRange (Iterator &&a, Iterator &&b)
 
IteratorRange< reverse_iteratorreversal () const
 
Iterator begin () const
 
Iterator end () const
 
reverse_iterator rbegin () const
 
reverse_iterator rend () const
 
bool empty () const
 
 operator bool () const
 
size_t size () const
 
template<typename T >
iterator find (const T &t) const
 
template<typename T >
long index (const T &t) const
 
template<typename T >
bool contains (const T &t) const
 
template<typename F >
iterator find_if (const F &f) const
 
template<typename F >
long index_if (const F &f) const
 
template<typename F >
bool all_of (const F &f) const
 
template<typename F >
bool any_of (const F &f) const
 
template<typename F >
bool none_of (const F &f) const
 
template<typename R , typename Binary = std::plus< R >, typename Unary = identity< decltype( *std::declval<Iterator>() ) >>
accumulate (R init, Binary binary_op={}, Unary unary_op={}) const
 
template<typename R , typename Binary = std::plus< R >, typename R2 , typename C >
accumulate (R init, Binary binary_op, R2(C ::*pmf)() const) const
 
template<typename Unary = identity< decltype( *std::declval<Iterator>() ) >, typename R = decltype( std::declval<Unary>()( *std::declval<Iterator>() ) )>
min (Unary unary_op={}) const
 
template<typename R2 , typename C , typename R = R2>
min (R2(C ::*pmf)() const) const
 
template<typename Unary = identity< decltype( *std::declval<Iterator>() ) >, typename R = decltype( std::declval<Unary>()( *std::declval<Iterator>() ) )>
max (Unary unary_op={}) const
 
template<typename R2 , typename C , typename R = R2>
max (R2(C ::*pmf)() const) const
 
template<typename Unary = identity< decltype( *std::declval<Iterator>() ) >, typename R = decltype( std::declval<Unary>()( *std::declval<Iterator>() ) )>
sum (Unary unary_op={}) const
 
template<typename R2 , typename C , typename R = R2>
sum (R2(C ::*pmf)() const) const
 

Detailed Description

template<typename Iterator>
struct IteratorRange< Iterator >

A convenience for use with range-for.

Definition at line 39 of file IteratorX.h.

Member Typedef Documentation

◆ iterator

template<typename Iterator >
using IteratorRange< Iterator >::iterator = Iterator

Definition at line 40 of file IteratorX.h.

◆ reverse_iterator

template<typename Iterator >
using IteratorRange< Iterator >::reverse_iterator = std::reverse_iterator<Iterator>

Definition at line 41 of file IteratorX.h.

Constructor & Destructor Documentation

◆ IteratorRange() [1/2]

template<typename Iterator >
IteratorRange< Iterator >::IteratorRange ( const Iterator &  a,
const Iterator &  b 
)
inline

Definition at line 43 of file IteratorX.h.

44 : std::pair<Iterator, Iterator> ( a, b ) {}

◆ IteratorRange() [2/2]

template<typename Iterator >
IteratorRange< Iterator >::IteratorRange ( Iterator &&  a,
Iterator &&  b 
)
inline

Definition at line 46 of file IteratorX.h.

47 : std::pair<Iterator, Iterator> ( std::move(a), std::move(b) ) {}

Member Function Documentation

◆ accumulate() [1/2]

template<typename Iterator >
template<typename R , typename Binary = std::plus< R >, typename R2 , typename C >
R IteratorRange< Iterator >::accumulate ( init,
Binary  binary_op,
R2(C ::*)() const  pmf 
) const
inline

Definition at line 131 of file IteratorX.h.

136 {
137 return this->accumulate( init, binary_op, std::mem_fn( pmf ) );
138 }
R accumulate(R init, Binary binary_op={}, Unary unary_op={}) const
Definition: IteratorX.h:112

References IteratorRange< Iterator >::accumulate().

Here is the call graph for this function:

◆ accumulate() [2/2]

template<typename Iterator >
template<typename R , typename Binary = std::plus< R >, typename Unary = identity< decltype( *std::declval<Iterator>() ) >>
R IteratorRange< Iterator >::accumulate ( init,
Binary  binary_op = {},
Unary  unary_op = {} 
) const
inline

Definition at line 112 of file IteratorX.h.

114 {},
115 Unary unary_op = {}
116 ) const
117 {
118 R result = init;
119 for (auto&& v : *this)
120 result = binary_op(result, unary_op(v));
121 return result;
122 }

Referenced by IteratorRange< Iterator >::accumulate().

Here is the caller graph for this function:

◆ all_of()

template<typename Iterator >
template<typename F >
bool IteratorRange< Iterator >::all_of ( const F &  f) const
inline

Definition at line 88 of file IteratorX.h.

89 {
90 auto notF =
91 [&](typename std::iterator_traits<Iterator>::reference v)
92 { return !f(v); };
93 return !this->any_of( notF );
94 }
bool any_of(const F &f) const
Definition: IteratorX.h:96

References IteratorRange< Iterator >::any_of().

Here is the call graph for this function:

◆ any_of()

template<typename Iterator >
template<typename F >
bool IteratorRange< Iterator >::any_of ( const F &  f) const
inline

Definition at line 96 of file IteratorX.h.

97 { return this->end() != this->find_if(f); }
iterator find_if(const F &f) const
Definition: IteratorX.h:76
Iterator end() const
Definition: IteratorX.h:53

References IteratorRange< Iterator >::end(), and IteratorRange< Iterator >::find_if().

Referenced by IteratorRange< Iterator >::all_of(), and IteratorRange< Iterator >::none_of().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ begin()

template<typename Iterator >
Iterator IteratorRange< Iterator >::begin ( ) const
inline

Definition at line 52 of file IteratorX.h.

52{ return this->first; }

Referenced by IteratorRange< Iterator >::empty(), IteratorRange< Iterator >::find(), IteratorRange< Iterator >::find_if(), IteratorRange< Iterator >::index(), IteratorRange< Iterator >::index_if(), MixAndRender(), and IteratorRange< Iterator >::size().

Here is the caller graph for this function:

◆ contains()

template<typename Iterator >
template<typename T >
bool IteratorRange< Iterator >::contains ( const T &  t) const
inline

Definition at line 73 of file IteratorX.h.

74 { return this->end() != this->find(t); }
iterator find(const T &t) const
Definition: IteratorX.h:62

References IteratorRange< Iterator >::end(), and IteratorRange< Iterator >::find().

Here is the call graph for this function:

◆ empty()

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

Definition at line 58 of file IteratorX.h.

58{ return this->begin() == this->end(); }
Iterator begin() const
Definition: IteratorX.h:52

References IteratorRange< Iterator >::begin(), and IteratorRange< Iterator >::end().

Referenced by MixAndRender(), and IteratorRange< Iterator >::operator bool().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ end()

template<typename Iterator >
Iterator IteratorRange< Iterator >::end ( ) const
inline

Definition at line 53 of file IteratorX.h.

53{ return this->second; }

Referenced by IteratorRange< Iterator >::any_of(), IteratorRange< Iterator >::contains(), IteratorRange< Iterator >::empty(), IteratorRange< Iterator >::find(), IteratorRange< Iterator >::find_if(), IteratorRange< Iterator >::index(), IteratorRange< Iterator >::index_if(), and IteratorRange< Iterator >::size().

Here is the caller graph for this function:

◆ find()

template<typename Iterator >
template<typename T >
iterator IteratorRange< Iterator >::find ( const T &  t) const
inline

Definition at line 62 of file IteratorX.h.

63 { return std::find(this->begin(), this->end(), t); }

References IteratorRange< Iterator >::begin(), and IteratorRange< Iterator >::end().

Referenced by IteratorRange< Iterator >::contains(), and IteratorRange< Iterator >::index().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_if()

template<typename Iterator >
template<typename F >
iterator IteratorRange< Iterator >::find_if ( const F &  f) const
inline

Definition at line 76 of file IteratorX.h.

77 { return std::find_if(this->begin(), this->end(), f); }

References IteratorRange< Iterator >::begin(), and IteratorRange< Iterator >::end().

Referenced by IteratorRange< Iterator >::any_of(), and IteratorRange< Iterator >::index_if().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ index()

template<typename Iterator >
template<typename T >
long IteratorRange< Iterator >::index ( const T &  t) const
inline

Definition at line 65 of file IteratorX.h.

66 {
67 auto iter = this->find(t);
68 if (iter == this->end())
69 return -1;
70 return std::distance(this->begin(), iter);
71 }

References IteratorRange< Iterator >::begin(), IteratorRange< Iterator >::end(), and IteratorRange< Iterator >::find().

Here is the call graph for this function:

◆ index_if()

template<typename Iterator >
template<typename F >
long IteratorRange< Iterator >::index_if ( const F &  f) const
inline

Definition at line 79 of file IteratorX.h.

80 {
81 auto iter = this->find_if(f);
82 if (iter == this->end())
83 return -1;
84 return std::distance(this->begin(), iter);
85 }

References IteratorRange< Iterator >::begin(), IteratorRange< Iterator >::end(), and IteratorRange< Iterator >::find_if().

Here is the call graph for this function:

◆ max() [1/2]

template<typename Iterator >
template<typename R2 , typename C , typename R = R2>
R IteratorRange< Iterator >::max ( R2(C ::*)() const  pmf) const
inline

Definition at line 180 of file IteratorX.h.

181 {
182 return this->max( std::mem_fn( pmf ) );
183 }
R max(Unary unary_op={}) const
Definition: IteratorX.h:167

References IteratorRange< Iterator >::max().

Here is the call graph for this function:

◆ max() [2/2]

template<typename Iterator >
template<typename Unary = identity< decltype( *std::declval<Iterator>() ) >, typename R = decltype( std::declval<Unary>()( *std::declval<Iterator>() ) )>
R IteratorRange< Iterator >::max ( Unary  unary_op = {}) const
inline

Definition at line 167 of file IteratorX.h.

167 {} ) const
168 {
169 return this->accumulate(
170 std::numeric_limits< R >::lowest(),
171 (const R&(*)(const R&, const R&)) std::max,
172 unary_op
173 );
174 }

Referenced by IteratorRange< Iterator >::max().

Here is the caller graph for this function:

◆ min() [1/2]

template<typename Iterator >
template<typename R2 , typename C , typename R = R2>
R IteratorRange< Iterator >::min ( R2(C ::*)() const  pmf) const
inline

Definition at line 158 of file IteratorX.h.

159 {
160 return this->min( std::mem_fn( pmf ) );
161 }
R min(Unary unary_op={}) const
Definition: IteratorX.h:145

References IteratorRange< Iterator >::min().

Here is the call graph for this function:

◆ min() [2/2]

template<typename Iterator >
template<typename Unary = identity< decltype( *std::declval<Iterator>() ) >, typename R = decltype( std::declval<Unary>()( *std::declval<Iterator>() ) )>
R IteratorRange< Iterator >::min ( Unary  unary_op = {}) const
inline

Definition at line 145 of file IteratorX.h.

145 {} ) const
146 {
147 return this->accumulate(
148 std::numeric_limits< R >::max(),
149 (const R&(*)(const R&, const R&)) std::min,
150 unary_op
151 );
152 }
int min(int a, int b)

Referenced by IteratorRange< Iterator >::min().

Here is the caller graph for this function:

◆ none_of()

template<typename Iterator >
template<typename F >
bool IteratorRange< Iterator >::none_of ( const F &  f) const
inline

Definition at line 99 of file IteratorX.h.

100 { return !this->any_of(f); }

References IteratorRange< Iterator >::any_of().

Here is the call graph for this function:

◆ operator bool()

template<typename Iterator >
IteratorRange< Iterator >::operator bool ( ) const
inlineexplicit

Definition at line 59 of file IteratorX.h.

59{ return !this->empty(); }
bool empty() const
Definition: IteratorX.h:58

References IteratorRange< Iterator >::empty().

Here is the call graph for this function:

◆ rbegin()

template<typename Iterator >
reverse_iterator IteratorRange< Iterator >::rbegin ( ) const
inline

Definition at line 55 of file IteratorX.h.

55{ return reverse_iterator{ this->second }; }
std::reverse_iterator< Iterator > reverse_iterator
Definition: IteratorX.h:41

Referenced by IteratorRange< Iterator >::reversal().

Here is the caller graph for this function:

◆ rend()

template<typename Iterator >
reverse_iterator IteratorRange< Iterator >::rend ( ) const
inline

Definition at line 56 of file IteratorX.h.

56{ return reverse_iterator{ this->first }; }

Referenced by IteratorRange< Iterator >::reversal().

Here is the caller graph for this function:

◆ reversal()

template<typename Iterator >
IteratorRange< reverse_iterator > IteratorRange< Iterator >::reversal ( ) const
inline

Definition at line 49 of file IteratorX.h.

50 { return { this->rbegin(), this->rend() }; }
reverse_iterator rend() const
Definition: IteratorX.h:56
reverse_iterator rbegin() const
Definition: IteratorX.h:55

References IteratorRange< Iterator >::rbegin(), and IteratorRange< Iterator >::rend().

Here is the call graph for this function:

◆ size()

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

Definition at line 60 of file IteratorX.h.

60{ return std::distance(this->begin(), this->end()); }

References IteratorRange< Iterator >::begin(), and IteratorRange< Iterator >::end().

Here is the call graph for this function:

◆ sum() [1/2]

template<typename Iterator >
template<typename R2 , typename C , typename R = R2>
R IteratorRange< Iterator >::sum ( R2(C ::*)() const  pmf) const
inline

Definition at line 202 of file IteratorX.h.

203 {
204 return this->sum( std::mem_fn( pmf ) );
205 }
R sum(Unary unary_op={}) const
Definition: IteratorX.h:189

References IteratorRange< Iterator >::sum().

Here is the call graph for this function:

◆ sum() [2/2]

template<typename Iterator >
template<typename Unary = identity< decltype( *std::declval<Iterator>() ) >, typename R = decltype( std::declval<Unary>()( *std::declval<Iterator>() ) )>
R IteratorRange< Iterator >::sum ( Unary  unary_op = {}) const
inline

Definition at line 189 of file IteratorX.h.

189 {} ) const
190 {
191 return this->accumulate(
192 R{ 0 },
193 std::plus< R >{},
194 unary_op
195 );
196 }

Referenced by IteratorRange< Iterator >::sum().

Here is the caller graph for this function:

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