mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-04 09:39:42 +02:00
Define and use utility template ValueIterator...
... generalizing the fix of commit 7591891 to other cases, making the iterators safe for adaptation with std::reverse_iterator should the need ever arise
This commit is contained in:
parent
b4ce681867
commit
d261ea2558
@ -430,6 +430,19 @@ template< typename T >
|
||||
ValueRestorer< T > valueRestorer( T& var, const T& newValue )
|
||||
{ return ValueRestorer< T >{ var, newValue }; }
|
||||
|
||||
/**
|
||||
\brief A convenience for defining iterators that return rvalue types, so that
|
||||
they cooperate correctly with stl algorithms and std::reverse_iterator
|
||||
*/
|
||||
template< typename Value, typename Category = std::forward_iterator_tag >
|
||||
using ValueIterator = std::iterator<
|
||||
Category, const Value, ptrdiff_t,
|
||||
// void pointer type so that operator -> is disabled
|
||||
void,
|
||||
// make "reference type" really the same as the value type
|
||||
const Value
|
||||
>;
|
||||
|
||||
/**
|
||||
\brief A convenience for use with range-for
|
||||
*/
|
||||
|
11
src/Track.h
11
src/Track.h
@ -834,16 +834,7 @@ template < typename TrackType > struct TrackIterRange;
|
||||
template <
|
||||
typename TrackType // Track or a subclass, maybe const-qualified
|
||||
> class TrackIter
|
||||
: public std::iterator<
|
||||
std::bidirectional_iterator_tag,
|
||||
TrackType *const,
|
||||
ptrdiff_t,
|
||||
// pointer is void to disable operator -> in the reverse_iterator...
|
||||
void,
|
||||
// ... because what operator * returns is really a value type,
|
||||
// so you can't take its address
|
||||
TrackType *const
|
||||
>
|
||||
: public ValueIterator< TrackType *, std::bidirectional_iterator_tag >
|
||||
{
|
||||
public:
|
||||
// Type of predicate taking pointer to const TrackType
|
||||
|
@ -378,7 +378,7 @@ private:
|
||||
// Get access to all clips (in some unspecified sequence),
|
||||
// including those hidden in cutlines.
|
||||
class AllClipsIterator
|
||||
: public std::iterator< std::forward_iterator_tag, WaveClip* >
|
||||
: public ValueIterator< WaveClip * >
|
||||
{
|
||||
public:
|
||||
// Constructs an "end" iterator
|
||||
|
@ -114,7 +114,7 @@ public:
|
||||
// This iterator visits the nodes of the forest in pre-order, and at each
|
||||
// stop, reports its Place
|
||||
class Iterator
|
||||
: public std::iterator<std::forward_iterator_tag, Place>
|
||||
: public ValueIterator<Place>
|
||||
{
|
||||
public:
|
||||
const Place &operator * () const { return mPlace; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user