(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 | ||||
span::subspan | ||||
| Non-member functions | ||||
| Non-member constant | ||||
| Deduction guides |
template<std::size_t Offset, std::size_t Count=std::dynamic_extent> | (1) | (since C++20) |
constexprstd::span<element_type,std::dynamic_extent> subspan( size_type offset, | (2) | (since C++20) |
Obtains a subview over some consecutive elements of this span, the elements to be included are determined by an element count and an offset.
IfOffset<= size()&&(Count==std::dynamic_extent|| Count<= size()- Offset) isfalse, the behavior is undefined. | (until C++26) |
IfOffset<= size()&&(Count==std::dynamic_extent|| Count<= size()- Offset) isfalse:
| (since C++26) |
Ifoffset<= size()&&(count==std::dynamic_extent|| count<= size()- offset) isfalse, the behavior is undefined. | (until C++26) |
Ifoffset<= size()&&(count==std::dynamic_extent|| count<= size()- offset) isfalse:
| (since C++26) |
#include <algorithm>#include <cstdio>#include <numeric>#include <ranges>#include <span> void display(std::span<constchar> abc){constauto columns{20U};constauto rows{abc.size()- columns+1}; for(auto offset{0U}; offset< rows;++offset){ std::ranges::for_each(abc.subspan(offset, columns),std::putchar);std::puts("");}} int main(){char abc[26]; std::ranges::iota(abc,'A'); display(abc);}
Output:
ABCDEFGHIJKLMNOPQRSTBCDEFGHIJKLMNOPQRSTUCDEFGHIJKLMNOPQRSTUVDEFGHIJKLMNOPQRSTUVWEFGHIJKLMNOPQRSTUVWXFGHIJKLMNOPQRSTUVWXYGHIJKLMNOPQRSTUVWXYZ
obtains a subspan consisting of the firstN elements of the sequence(public member function)[edit] | |
obtains a subspan consisting of the lastN elements of the sequence(public member function)[edit] |