QDirListing: simplify const_iterator
There's no need to carry the same QDirListingPrivate* around twice. Remove const_iterator's direct QDirListingPrivate* member and re-use the one from its DirEntry member. Requires adding a private const_iterator::atEnd() helper function, because while const_iterator and its member functions are implicit friends of DirEntry, friend functions of const_iterator are not. Improves readability, too. Found in API-review. Change-Id: I82b9273950e174d7598ee531fbd5dfb472911b71 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> (cherry picked from commit 0ede7f541dfc6cba163e1452aee7239818a42c1b) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
089263fd4f
commit
5cb51e4afe
@ -725,8 +725,8 @@ QDirListing::const_iterator QDirListing::begin() const
|
|||||||
*/
|
*/
|
||||||
QDirListing::const_iterator &QDirListing::const_iterator::operator++()
|
QDirListing::const_iterator &QDirListing::const_iterator::operator++()
|
||||||
{
|
{
|
||||||
dirListPtr->advance();
|
dirEntry.dirListPtr->advance();
|
||||||
if (!dirListPtr->hasIterators())
|
if (!dirEntry.dirListPtr->hasIterators())
|
||||||
*this = {}; // All done, make `this` equal to the end() iterator
|
*this = {}; // All done, make `this` equal to the end() iterator
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -103,8 +103,7 @@ public:
|
|||||||
class const_iterator
|
class const_iterator
|
||||||
{
|
{
|
||||||
friend class QDirListing;
|
friend class QDirListing;
|
||||||
const_iterator(QDirListingPrivate *dp) : dirListPtr(dp) { dirEntry.dirListPtr = dp; }
|
explicit const_iterator(QDirListingPrivate *dp) { dirEntry.dirListPtr = dp; }
|
||||||
QDirListingPrivate *dirListPtr = nullptr;
|
|
||||||
DirEntry dirEntry;
|
DirEntry dirEntry;
|
||||||
public:
|
public:
|
||||||
using iterator_category = std::input_iterator_tag;
|
using iterator_category = std::input_iterator_tag;
|
||||||
@ -118,10 +117,9 @@ public:
|
|||||||
pointer operator->() const { return &dirEntry; }
|
pointer operator->() const { return &dirEntry; }
|
||||||
Q_CORE_EXPORT const_iterator &operator++();
|
Q_CORE_EXPORT const_iterator &operator++();
|
||||||
const_iterator operator++(int) { auto tmp = *this; operator++(); return tmp; };
|
const_iterator operator++(int) { auto tmp = *this; operator++(); return tmp; };
|
||||||
friend bool operator==(const const_iterator &lhs, sentinel) noexcept
|
private:
|
||||||
{
|
bool atEnd() const noexcept { return dirEntry.dirListPtr == nullptr; }
|
||||||
return lhs.dirListPtr == nullptr;
|
friend bool operator==(const const_iterator &lhs, sentinel) noexcept { return lhs.atEnd(); }
|
||||||
}
|
|
||||||
#ifndef __cpp_impl_three_way_comparison
|
#ifndef __cpp_impl_three_way_comparison
|
||||||
friend bool operator!=(const const_iterator &lhs, sentinel) noexcept
|
friend bool operator!=(const const_iterator &lhs, sentinel) noexcept
|
||||||
{ return !operator==(lhs, sentinel{}); }
|
{ return !operator==(lhs, sentinel{}); }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user