(C++17) | ||||
| Sequence | ||||
(C++11) | ||||
(C++26) | ||||
(C++26) | ||||
(C++11) | ||||
| Associative | ||||
| Unordered associative | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
| Adaptors | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
| Views | ||||
(C++20) | ||||
(C++23) | ||||
| Tables | ||||
| Iterator invalidation | ||||
| Member function table | ||||
| Non-member function table |
| Member functions | ||||
| Element access | ||||
(C++26) | ||||
| Iterators | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
| Observers | ||||
| Subviews | ||||
| Non-member functions | ||||
| Non-member constant | ||||
dynamic_extent | ||||
| Deduction guides |
Defined in header <span> | ||
inlineconstexprstd::size_t dynamic_extent=std::numeric_limits<std::size_t>::max(); | (since C++20) | |
std::dynamic_extent is a constant of typestd::size_t that is generally used to indicate that any type usingstd::dynamic_extent willdynamically store its value (e.g., size) rather than having the valuestatically known in the type.
It is being used in several contexts:
| (since C++23) |
| (since C++26) |
Sincestd::size_t is an unsigned type, an equivalent definition is:
inlineconstexprstd::size_t dynamic_extent=-1;
#include <array>#include <cassert>#include <cstddef>#include <iostream>#include <span>#include <string_view>#include <vector> int main(){auto print=[](std::string_viewconst name,std::size_t ex){std::cout<< name<<", ";if(std::dynamic_extent== ex)std::cout<<"dynamic extent\n";elsestd::cout<<"static extent = "<< ex<<'\n';}; int a[]{1,2,3,4,5}; std::span span1{a}; print("span1", span1.extent); std::span<int, std::dynamic_extent> span2{a}; print("span2", span2.extent); std::array ar{1,2,3,4,5};std::span span3{ar}; print("span3", span3.extent); std::vector v{1,2,3,4,5};std::span span4{v}; print("span4", span4.extent);}
Output:
span1, static extent = 5span2, dynamic extentspan3, static extent = 5span4, dynamic extent
(C++20) | a non-owning view over a contiguous sequence of objects (class template)[edit] |
(C++23) | a descriptor of a multidimensional index space of some rank (class template)[edit] |