我知道 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/