Define and use IteratorRange

This commit is contained in:
Paul Licameli 2016-08-11 13:06:39 -04:00
parent 90e400b0a7
commit 6909bdf398
3 changed files with 14 additions and 8 deletions

View File

@ -727,4 +727,16 @@ Final_action<F> finally (F f)
return Final_action<F>(f);
}
/*
* A convenience for use with range-for
*/
template <typename Iterator>
struct IteratorRange : public std::pair<Iterator, Iterator> {
IteratorRange (Iterator &&a, Iterator &&b)
: std::pair<Iterator, Iterator> { std::move(a), std::move(b) } {}
Iterator begin() const { return this->first; }
Iterator end() const { return this->second; }
};
#endif // __AUDACITY_MEMORY_X_H__

View File

@ -443,7 +443,7 @@ wxString Tags::GetTag(const wxString & name) const
Tags::Iterators Tags::GetRange() const
{
return std::make_pair(mMap.begin(), mMap.end());
return { mMap.begin(), mMap.end() };
}
void Tags::SetTag(const wxString & name, const wxString & value)

View File

@ -104,13 +104,7 @@ class AUDACITY_DLL_API Tags final : public XMLTagHandler {
bool HasTag(const wxString & name) const;
wxString GetTag(const wxString & name) const;
using IterPair = std::pair<TagMap::const_iterator, TagMap::const_iterator>;
struct Iterators : public IterPair {
Iterators(IterPair p) : IterPair(p) {}
// Define begin() and end() for convenience in range-for
auto begin() -> decltype(first) const { return first; }
auto end() -> decltype(second) const { return second; }
};
using Iterators = IteratorRange<TagMap::const_iterator>;
Iterators GetRange() const;
void SetTag(const wxString & name, const wxString & value);