1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-04 01:29:43 +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:
Paul Licameli 2018-12-22 09:35:22 -05:00
parent b4ce681867
commit d261ea2558
4 changed files with 16 additions and 12 deletions

View File

@ -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
*/

View File

@ -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

View File

@ -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

View File

@ -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; }