c++ - 为什么 std::span 缺少 size_type?

标签 c++ c++20 std-span

我一直在将使用我的自制 span 类的旧代码更新为更符合 C++20 std::span 的代码,但我遇到了编译错误,因为 std::span 没有 size_type 而是有 index_type。关于 index_type 是否应该签名的问题一直存在争议,但为什么要跳过 size_type?这打破了期望容器(或类似容器的对象)具有 size_type 的通用代码。

最佳答案

原提案P1022R0 ,当它被称为 array_view 时,有一个 size_type 成员。它在第一次修订中被删除了 P1022R1作为简化的一部分,因为当时不需要 size() 和元素访问,使用带符号的 index_type(又名 ptrdiff_t)。在科纳 2019 年 session 上,该决定在 P1227R2 中发生了变化。通过将 index_type 更改为 size_t

关于c++ - 为什么 std::span 缺少 size_type?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55209261/

相关文章:

c++ - 为什么 int main() {} 编译?

c++ - 尽管资源存在,但 FindResource() 函数失败

c++ - 将非拥有位容器基于 std::vector<bool> 是一个好主意吗?标准::跨度?

c++ - 为什么span的数组和std::array构造函数与其容器构造函数不同

c++ - 在 Geany 中使用 OpenGL 时获取 undefined reference

c++ - 在 boost transformed() 之后比较嵌套迭代器

c++ - 了解什么是原子约束

c++ - 什么是 consteval?

c++ - 为什么在 C++20 中删除了许多标准库类型的运算符!=?

c++ - 为什么 C++20 知道如何对 string_view 进行哈希处理,但不知道如何对 span<char> 进行哈希处理?