List: Add Sort Functions (#1160)

This commit is contained in:
complexlogic
2023-10-18 05:54:22 +00:00
committed by GitHub
parent b40b834b1b
commit 1d213b8b98
3 changed files with 52 additions and 0 deletions

View File

@ -276,6 +276,19 @@ namespace TagLib {
*/
bool operator!=(const List<T> &l) const;
/*!
* Sorts this list in ascending order using operator< of T.
*/
void sort();
/*!
* Sorts this list in ascending order using the comparison
* function object \a comp which returns true if the first argument is
* less than the second.
*/
template<class Compare>
void sort(Compare&& comp);
protected:
/*
* If this List is being shared via implicit sharing, do a deep copy of the

View File

@ -330,6 +330,21 @@ bool List<T>::operator!=(const List<T> &l) const
return d->list != l.d->list;
}
template <class T>
void List<T>::sort()
{
detach();
d->list.sort();
}
template <class T>
template <class Compare>
void List<T>::sort(Compare&& comp)
{
detach();
d->list.sort(std::forward<Compare>(comp));
}
////////////////////////////////////////////////////////////////////////////////
// protected members
////////////////////////////////////////////////////////////////////////////////