在 STL 迭代器的上下文中,什么是奇异值和非奇异值? [英] What is singular and non-singular values in the context of STL iterators?

查看:25
本文介绍了在 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 迭代器的上下文中,什么是奇异值和非奇异值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆