What is singular and non-singular values in the context of STL iterators?(在 STL 迭代器的上下文中,什么是奇异值和非奇异值?)
问题描述
C++ 标准 (2003) 的第 24.1/5 节内容如下:
The section §24.1/5 from the C++ Standard (2003) reads,
就像一个指向数组的常规指针保证有一个指针指向最后一个元素的值数组的,所以对于任何迭代器类型有一个迭代器值指向过去 a 的最后一个元素对应的容器.这些值被称为过去的值.价值观迭代器 i 的表达式 *i 被定义被调用可取消引用.图书馆从不假设过去的值是可取消引用.迭代器也可以具有不存在的奇异值与任何容器相关联.[示例:在声明一个未初始化的指针 x(与 int* 一样)x;), x 必须总是假设有一个指针的奇异值.]大多数表达式的结果是奇异值未定义;这唯一的例外是分配 a迭代器的非奇异值持有奇异值.在这种情况下奇异值被覆盖与任何其他值相同.可取消引用的值总是非单数.
Just as a regular pointer to an array guarantees that there is a pointer value pointing past the last element of the array, so for any iterator type there is an iterator value that points past the last element of a corresponding container. These values are called past-the-end values. Values of an iterator i for which the expression *i is defined are called dereferenceable. The library never assumes that past-the-end values are dereferenceable. Iterators can also have singular values that are not associated with any container. [Example: After the declaration of an uninitialized pointer x (as with int* x;), x must always be assumed to have a singular value of a pointer.] Results of most expressions are undefined for singular values; the only exception is an assignment of a non-singular value to an iterator that holds a singular value. In this case the singular value is overwritten the same way as any other value. Dereferenceable values are always nonsingular.
我无法真正理解 粗体 中显示的文字?
I couldn't really understand the text shown in bold?
- 什么是奇异值和非奇异值?它们是如何定义的?在哪里?
- 为什么可解引用的值是总是非单数的?
- What is singular value and nonsingular value? How are they defined? And where?
- How and why dereferenceable values are always nonsingular?
推荐答案
迭代器也可以有奇异值不与任何容器相关联.
我想这就是它的定义.
可取消引用的值如何以及为什么总是非奇异的?
How and why dereferenceable values are always nonsingular?
因为如果他们不这样做,取消引用它们将是未定义的行为.
Because if they wouldn't, dereferencing them would be undefined behavior.
这篇关于在 STL 迭代器的上下文中,什么是奇异值和非奇异值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 STL 迭代器的上下文中,什么是奇异值和非奇异值?
基础教程推荐
- C++ 程序在执行 std::string 分配时总是崩溃 2022-01-01
- C++,'if' 表达式中的变量声明 2021-01-01
- C++ 标准:取消引用 NULL 指针以获取引用? 2021-01-01
- 运算符重载的基本规则和习语是什么? 2022-10-31
- 什么是T&&(双与号)在 C++11 中是什么意思? 2022-11-04
- 您如何将 CreateThread 用于属于类成员的函数? 2021-01-01
- 如何定义双括号/双迭代器运算符,类似于向量的向量? 2022-01-01
- 如何在 C++ 中处理或避免堆栈溢出 2022-01-01
- 调用std::Package_TASK::Get_Future()时可能出现争用情况 2022-12-17
- 设计字符串本地化的最佳方法 2022-01-01