c++ - std::span 中 std::dynamic_extent 的用途是什么

标签 c++ std std-span

我知道 std::span 是静态的。它只是一堆 vector/数组/等的 View 。元素。

我明白了constructors的span,看起来4-6中使用了std::dynamic_extent。但在这些构造函数中,有一个必需的大小模板参数 - std::size_t N。对我来说,这意味着大小/计数/长度在编译时是已知的。那么 std::dynamic_extent 到底是什么?

最佳答案

的定义是 std::dynamic_extent

inline constexpr std::size_t dynamic_extent 
    = std::numeric_limits<std::size_t>::max();

它是 std::size_t 的特殊值,用于指示 std::span 具有动态范围。

There is a required template argument for the size - std::size_t N. To me this means that the size/count/len is known at compile time.

std::span 的“大小”仍然在编译时指定,只是当“大小”采用该特殊值时,它被视为动态范围。

关于c++ - std::span 中 std::dynamic_extent 的用途是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76839400/

相关文章:

c++ - 如何初始化 std::span<const T*>?常量问题

c++ - 如何正确设计工作线程? (例如避免 sleep (1))

c++ - GetInterfaceFromGlobal() 调用因 Visual Studio 2010 中的进程外 COM 服务器而失败

C++ 在给定的日期和时间运行函数

c++ - 如何最有效地从具有大小的 char * 构造 std::string

c++ - 每当应用程序崩溃时为其创建转储文件

c++ - 位摆弄 : find next power of two with templates in c++

c++ - 将构造函数转换为函数的返回值

c++ - 如何使用 span 来包装命令行参数

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