const_iterator Class

class QDirListing::const_iterator

This class was introduced in Qt 6.8.

Public Types

Public Functions

QDirListing::const_iterator::reference operator*() const
QDirListing::const_iterator &operator++()
void operator++(int)
QDirListing::const_iterator::pointer operator->() const

Detailed Description

The iterator type returned by QDirListing::cbegin().

  • This is a forward-only, single-pass iterator (you cannot iterate directory entries in reverse order)
  • Can't be copied, only std::move()d.
  • The return value of post-increment on objects that model std::input_iterator is partially-formed (a copy of an iterator that has since been advanced), the only valid operations on such an object are destruction and assignment of a new iterator. Therefore the post-increment operator advances the iterator and returns void.
  • Doesn't allow random access
  • Can be used in ranged-for loops; or with C++20 std::ranges algorithms that don't require random access iterators
  • Dereferencing a valid iterator returns a const DirEntry &
  • (c)end() returns a QDirListing::sentinel that signals the end of the iteration. Dereferencing an iterator that compares equal to end() is undefined behavior

Note: The "classical" STL algorithms don't support iterator/sentinel, so you need to use C++20 std::ranges algorithms for QDirListing, or else a 3rd-party library that provides range-based algorithms in C++17.

See also QDirListing, QDirListing::sentinel, and QDirListing::DirEntry.

Member Type Documentation

[alias] const_iterator::pointer

A typedef for const QDirListing::DirEntry *.

[alias] const_iterator::reference

A typedef for const QDirListing::DirEntry &.

Member Function Documentation

QDirListing::const_iterator::reference const_iterator::operator*() const

Returns a const QDirListing::DirEntry & of the directory entry this iterator points to.

QDirListing::const_iterator &const_iterator::operator++()

Pre-increment operator. Advances the iterator and returns a reference to it.

void const_iterator::operator++(int)

Post-increment operator.

QDirListing::const_iterator models C++20 std::input_iterator, that is, it is a move-only, forward-only, single-pass iterator, that doesn't allow random access.

The return value of post-increment on objects that model std::input_iterator is partially-formed (a copy of an iterator that has since been advanced), the only valid operations on such an object are destruction and assignment of a new iterator. Therefore the post-increment operator advances the iterator and returns void.

QDirListing::const_iterator::pointer const_iterator::operator->() const

Returns a const QDirListing::DirEntry * to the directory entry this iterator points to.

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.