std::span::size(3)
π std::span::size π
okay so bestie, this is the <std::span::size>(3) page from the C++ Standard Libary β yes, thatβs the spelling in the header, and weβre keeping it π
. Itβs giving βtiny member function, main character energy,β and weβre gonna get through every detail together, fr fr. β¨
π NAME π
std::span::size β literally std::span::size. Thatβs the name, bestie. No plot twist, no secret second identity. π
πΈ Synopsis πΈ
Hereβs the signature, and yes itβs constexpr, const noexcept, and since C++20 β the whole slay package π₯:
constexpr size_type size() const noexcept; (since C++20)
It returns the number of elements in the span. Thatβs the vibe. π¦
π Parameters π
(none) β not a single parameter, zero, nada, the void, and we respect it π«Ά.
π Return value π
It returns the number of elements in the span β thatβs the whole return value, bestie π.
β Note β
Feature-test macro tea β:
- Feature-test macro:
__cpp_lib_ssize- Value:
201902L - Std:
(C++20) - Feature:
std::ssizeand unsignedstd::span::size
- Value:
π Example π
// Run this code
#include <iostream>
#include <span>
void show_sizes(std::span<const int> span)
{
std::cout
<< span .size() << ' ' // 8
<< span.first(7) .size() << ' ' // 7
<< span.first<6>() .size() << ' ' // 6
<< span.last(5) .size() << ' ' // 5
<< span.last<4>() .size() << ' ' // 4
<< span.subspan(2, 3) .size() << ' ' // 3
<< span.subspan<3, 2>() .size() << ' ' // 2
<< '\n';
}
int main()
{
int antique_array[]{1, 2, 3, 4, 5, 6, 7, 8};
show_sizes(antique_array);
}
Output:
8 7 6 5 4 3 2
π¦ See also π¦
constructorβ constructs a span (public member function) π οΈsize_bytesβ returns the size of the sequence in bytes (public member function) π
later bestie! this page is from http://cppreference.com, dated 2024.06.10, and the footer says std::span::size(3) β mwah πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms