QJsonArray::const_iterator Class

class QJsonArray::const_iterator

QJsonArray::const_iterator 类为QJsonArray 提供了 STL 风格的常量迭代器。更多

该类具有很强的可比性

该类与QJsonArray::iterator 具有很强的可比性

公共类型

公共函数

const_iterator()
const_iterator(const QJsonArray::iterator &other)
const QJsonValueConstRef operator*() const
QJsonArray::const_iterator operator+(qsizetype j) const
QJsonArray::const_iterator &operator++()
QJsonArray::const_iterator operator++(int)
QJsonArray::const_iterator &operator+=(qsizetype j)
qsizetype operator-(QJsonArray::const_iterator other) const
QJsonArray::const_iterator operator-(qsizetype j) const
QJsonArray::const_iterator &operator--()
QJsonArray::const_iterator operator--(int)
QJsonArray::const_iterator &operator-=(qsizetype j)
const QJsonValueConstRef *operator->() const
QJsonValueConstRef operator[](qsizetype j) const
bool operator!=(const QJsonArray::const_iterator &lhs, const QJsonArray::const_iterator &rhs)
bool operator<(const QJsonArray::const_iterator &lhs, const QJsonArray::const_iterator &rhs)
bool operator<=(const QJsonArray::const_iterator &lhs, const QJsonArray::const_iterator &rhs)
bool operator==(const QJsonArray::const_iterator &lhs, const QJsonArray::const_iterator &rhs)
bool operator>(const QJsonArray::const_iterator &lhs, const QJsonArray::const_iterator &rhs)
bool operator>=(const QJsonArray::const_iterator &lhs, const QJsonArray::const_iterator &rhs)

详细描述

QJsonArray::const_iterator 允许您遍历 。如果您想在遍历过程中修改 ,请使用 。一般来说,除非需要通过迭代器修改 ,否则在非 Const 上使用 也是一种好的做法。常量迭代器的速度稍快,并能提高代码的可读性。QJsonArray QJsonArray QJsonArray::iterator QJsonArray QJsonArray QJsonArray::const_iterator

默认的QJsonArray::const_iterator 构造函数会创建一个未初始化的迭代器。在开始迭代之前,必须使用QJsonArray 函数(如QJsonArray::constBegin()、QJsonArray::constEnd() 或QJsonArray::insert() )对其进行初始化。

大多数QJsonArray 函数接受的是整数索引而不是迭代器。因此,迭代器在QJsonArray 中很少有用。STL 样式的迭代器确实有用的一个地方是作为generic algorithms 的参数。

在同一个数组中可以使用多个迭代器。不过,请注意在QJsonArray 上执行的任何非const函数调用都会导致所有现有的迭代器都未定义。

另请参阅 QJsonArray::iterator

成员类型文档

const_iterator::iterator_category

std::random_access_iterator_tag的同义词,表示该迭代器是随机访问迭代器。

成员函数文档

const_iterator::const_iterator()

构造一个未初始化的迭代器。

不应在未初始化的迭代器上调用 operator*() 和 operator++() 等函数。在使用迭代器之前,请使用 operator=() 为其赋值。

另请参阅 QJsonArray::constBegin() 和QJsonArray::constEnd()。

const_iterator::const_iterator(const QJsonArray::iterator &other)

构造other 的副本。

const QJsonValueConstRef const_iterator::operator*() const

返回当前项目。

QJsonArray::const_iterator const_iterator::operator+(qsizetype j) const

返回一个迭代器,指向从该迭代器向前j 位置的项目。如果j 为负数,则迭代器会向后退。

另请参阅 operator-() 和operator+=()。

QJsonArray::const_iterator &const_iterator::operator++()

++ 前缀操作符++it 将迭代器前进到数组中的下一个项,并返回一个指向新的当前项的迭代器。

QJsonArray::end() 上调用此函数会导致未定义的结果。

另请参见 operator--()。

QJsonArray::const_iterator const_iterator::operator++(int)

这是一个重载函数。

后缀++ 运算符it++ 将迭代器前进到数组中的下一个项目,并返回一个指向先前当前项目的迭代器。

QJsonArray::const_iterator &const_iterator::operator+=(qsizetype j)

通过j 项目推进迭代器。如果j 为负数,则迭代器向后退。

另请参阅 operator-=() 和operator+()。

qsizetype const_iterator::operator-(QJsonArray::const_iterator other) const

返回other 指向的项目与此迭代器指向的项目之间的项目个数。

QJsonArray::const_iterator const_iterator::operator-(qsizetype j) const

返回一个迭代器,指向从该迭代器向后位于j 位置的项目。如果j 为负数,则迭代器向前移动。

另请参阅 operator+() 和operator-=()。

QJsonArray::const_iterator &const_iterator::operator--()

前缀-- 运算符--it 使前一项成为当前项,并返回一个指向新的当前项的迭代器。

QJsonArray::begin() 上调用此函数会导致未定义的结果。

另请参见 operator++()。

QJsonArray::const_iterator const_iterator::operator--(int)

这是一个重载函数。

后缀-- 运算符it-- 使前一个项目成为当前项目,并返回一个指向前一个当前项目的迭代器。

QJsonArray::const_iterator &const_iterator::operator-=(qsizetype j)

使迭代器返回j 项。如果j 为负数,则迭代器向前移动。

另请参阅 operator+=() 和operator-()。

const QJsonValueConstRef *const_iterator::operator->() const

返回指向当前项目的指针。

QJsonValueConstRef const_iterator::operator[](qsizetype j) const

返回从该迭代器指向的项目(位置*this + j 上的项目)出发,偏移量j 上的项目。

提供该函数是为了使QJsonArray 迭代器的行为类似于 C++ 指针。

另请参阅 operator+() 。

相关非成员

[noexcept] bool operator!=(const QJsonArray::const_iterator &lhs, const QJsonArray::const_iterator &rhs)

如果lhs 指向与rhs 迭代器不同的项目,则返回true ;否则返回false

另请参阅 operator==() 。

[noexcept] bool operator<(const QJsonArray::const_iterator &lhs, const QJsonArray::const_iterator &rhs)

如果lhs iterator 指向的项目小于rhs iterator 指向的项目,则返回true

[noexcept] bool operator<=(const QJsonArray::const_iterator &lhs, const QJsonArray::const_iterator &rhs)

如果lhs iterator 指向的项目小于或等于rhs iterator 指向的项目,则返回true

[noexcept] bool operator==(const QJsonArray::const_iterator &lhs, const QJsonArray::const_iterator &rhs)

如果lhs 指向与rhs 迭代器相同的项目,则返回true ;否则返回false

另请参阅 operator!=() 。

[noexcept] bool operator>(const QJsonArray::const_iterator &lhs, const QJsonArray::const_iterator &rhs)

如果lhs 迭代器指向的项目大于rhs 迭代器指向的项目,则返回true

[noexcept] bool operator>=(const QJsonArray::const_iterator &lhs, const QJsonArray::const_iterator &rhs)

如果lhs iterator 指向的项目大于或等于rhs iterator 指向的项目,则返回true

© 2025 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.