【发布时间】:2018-06-05 14:02:29
【问题描述】:
C++20 包括std::span, which "describes an object that can refer to a contiguous sequence of objects with the first element of the sequence at position zero"。它的界面非常接近std::array,虽然它支持动态范围以及固定范围。
明显的区别在于std::array 拥有它的元素(因此它的析构函数会销毁它们)而std::span 没有。
还有什么array 可以用于span 不能用的吗?
【问题讨论】:
-
不是跨度不同的用例吗?我可能错了,但我认为 span 就像
string_viewforstrings -
Span 的原因完全不同。 Span 基本上是 C++ 动态数组的一个安全习惯用法 - 封装指向序列开始和结束的指针。
-
span是array什么string_view它是string。array可用于复制内存,而span仅操作它的句柄。 -
“有什么
int可以用于int*不能用的吗?”