12#ifndef __AUDACITY_ITERATOR_X__
13#define __AUDACITY_ITERATOR_X__
24template<
typename Value,
typename Category = std::forward_iterator_tag >
38template <
typename Iterator>
44 :
std::pair<Iterator, Iterator> ( a, b ) {}
47 :
std::pair<Iterator, Iterator> (
std::move(a),
std::move(b) ) {}
52 Iterator
begin()
const {
return this->first; }
53 Iterator
end()
const {
return this->second; }
59 explicit operator bool ()
const {
return !this->
empty(); }
60 size_t size()
const {
return std::distance(this->
begin(), this->
end()); }
63 {
return std::find(this->
begin(), this->
end(), t); }
65 template <
typename T>
long index(
const T &t)
const
67 auto iter = this->
find(t);
68 if (iter == this->
end())
70 return std::distance(this->
begin(), iter);
73 template <
typename T>
bool contains(
const T &t)
const
74 {
return this->
end() != this->
find(t); }
77 {
return std::find_if(this->
begin(), this->
end(), f); }
79 template <
typename F>
long index_if(
const F &f)
const
82 if (iter == this->
end())
84 return std::distance(this->
begin(), iter);
88 template <
typename F>
bool all_of(
const F &f)
const
91 [&](
typename std::iterator_traits<Iterator>::reference v)
93 return !this->
any_of( notF );
96 template <
typename F>
bool any_of(
const F &f)
const
99 template <
typename F>
bool none_of(
const F &f)
const
100 {
return !this->
any_of(f); }
103 {
const T&&
operator () (T &&v)
const {
return std::forward(v); } };
109 typename Binary = std::plus< R >,
114 Binary binary_op = {},
119 for (
auto&& v : *
this)
120 result = binary_op(result, unary_op(v));
128 typename Binary = std::plus< R >,
129 typename R2,
typename C
134 R2 (
C :: * pmf) ()
const
137 return this->
accumulate( init, binary_op, std::mem_fn( pmf ) );
142 typename Unary = identity< decltype( *std::declval<Iterator>() ) >,
143 typename R =
decltype( std::declval<Unary>()( *std::declval<Iterator>() ) )
145 R
min( Unary unary_op = {} )
const
148 std::numeric_limits< R >::max(),
149 (
const R&(*)(
const R&,
const R&))
std::min,
155 typename R2,
typename C,
158 R
min( R2 (
C :: * pmf) ()
const )
const
160 return this->
min( std::mem_fn( pmf ) );
164 typename Unary = identity< decltype( *std::declval<Iterator>() ) >,
165 typename R =
decltype( std::declval<Unary>()( *std::declval<Iterator>() ) )
167 R
max( Unary unary_op = {} )
const
170 std::numeric_limits< R >::lowest(),
171 (
const R&(*)(
const R&,
const R&)) std::max,
177 typename R2,
typename C,
180 R
max( R2 (
C :: * pmf) ()
const )
const
182 return this->
max( std::mem_fn( pmf ) );
186 typename Unary = identity< decltype( *std::declval<Iterator>() ) >,
187 typename R =
decltype( std::declval<Unary>()( *std::declval<Iterator>() ) )
189 R
sum( Unary unary_op = {} )
const
199 typename R2,
typename C,
202 R
sum( R2 (
C :: * pmf) ()
const )
const
204 return this->
sum( std::mem_fn( pmf ) );
208template<
typename Iterator>
215template<
typename Container >
219 return { container.begin(), container.end() };
222template<
typename Container >
226 return { container.begin(), container.end() };
230template<
typename Container,
typename Iterator,
typename Function >
234 std::transform( first, last, std::back_inserter( result ),
fn );
238template<
typename OutContainer,
typename InContainer,
typename Function >
241 return transform_range<OutContainer>(
242 inContainer.begin(), inContainer.end(),
fn );
245template<
typename Range,
typename Function>
248 std::for_each(range.begin(), range.end(), std::forward<Function>(
fn));
251template<
typename Integral =
int>
260 {
auto result = *
this; ++result;
return result; }
265 {
return !(x == y); }
274 IotaRange(Integral inclusiveLower, Integral exclusiveUpper)
Container transform_range(Iterator first, Iterator last, Function &&fn)
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
void for_each_in_range(Range &&range, Function &&fn)
OutContainer transform_container(InContainer &inContainer, Function &&fn)
friend bool operator==(NumberIterator x, NumberIterator y)
NumberIterator & operator++()
Integral operator*() const
friend bool operator!=(NumberIterator x, NumberIterator y)
NumberIterator(Integral value)
IotaRange(Integral inclusiveLower, Integral exclusiveUpper)
const T && operator()(T &&v) const
A convenience for use with range-for.
R accumulate(R init, Binary binary_op, R2(C ::*pmf)() const) const
bool contains(const T &t) const
R sum(R2(C ::*pmf)() const) const
R sum(Unary unary_op={}) const
R accumulate(R init, Binary binary_op={}, Unary unary_op={}) const
bool all_of(const F &f) const
std::reverse_iterator< Iterator > reverse_iterator
iterator find_if(const F &f) const
iterator find(const T &t) const
IteratorRange(Iterator &&a, Iterator &&b)
long index(const T &t) const
R max(Unary unary_op={}) const
IteratorRange< reverse_iterator > reversal() const
R min(R2(C ::*pmf)() const) const
bool any_of(const F &f) const
long index_if(const F &f) const
reverse_iterator rend() const
bool none_of(const F &f) const
R min(Unary unary_op={}) const
IteratorRange(const Iterator &a, const Iterator &b)
reverse_iterator rbegin() const
R max(R2(C ::*pmf)() const) const
A convenience for defining iterators that return rvalue types, so that they cooperate correctly with ...
ptrdiff_t difference_type
Category iterator_category