std::span<T,Extent>:: first
|
template
<
std::
size_t
Count
>
constexpr std:: span < element_type, Count > first ( ) const ; |
(1) | (C++20부터) |
|
constexpr
std::
span
<
element_type,
std::
dynamic_extent
>
first ( size_type count ) const ; |
(2) | (C++20부터) |
이 스팬의 첫 번째 Count 또는 count 개 요소에 대한 서브뷰를 획득합니다.
|
만약 Count > size ( ) 또는 count > size ( ) 가 true 인 경우, 동작은 정의되지 않습니다. |
(C++26 이전) |
|
만약 Count > size ( ) 또는 count > size ( ) 가 true 인 경우: |
(C++26 이후) |
목차 |
매개변수
| count | - | 서브뷰의 요소 개수 |
반환값
예제
#include <iostream> #include <ranges> #include <span> #include <string_view> void print(const std::string_view title, const std::ranges::forward_range auto& container) { auto size{std::size(container)}; std::cout << title << '[' << size << "]{"; for (const auto& elem : container) std::cout << elem << (--size ? ", " : ""); std::cout << "};\n"; } void run_game(std::span<const int> span) { print("span: ", span); std::span<const int, 5> span_first = span.first<5>(); print("span.first<5>(): ", span_first); std::span<const int, std::dynamic_extent> span_first_dynamic = span.first(4); print("span.first(4): ", span_first_dynamic); } int main() { int a[8]{1, 2, 3, 4, 5, 6, 7, 8}; print("int a", a); run_game(a); }
출력:
int a[8]{1, 2, 3, 4, 5, 6, 7, 8};
span: [8]{1, 2, 3, 4, 5, 6, 7, 8};
span.first<5>(): [5]{1, 2, 3, 4, 5};
span.first(4): [4]{1, 2, 3, 4};
참고 항목
시퀀스의 마지막
N
개 요소로 구성된 부분 스팬을 얻음
(public member function) |
|
|
부분 스팬을 얻음
(public member function) |