std::ranges..._view::size(3)
π
std::ranges..._view::size(3) β C++ Standard Libary energy β¨
Hey bestie, welcome to the C++ Standard Libary page for std::ranges..._view::size(3). No cap, this is the size member of std::ranges::adjacent_view, and she's here to tell you how many elements are in the house. π«Ά
π NAME π
std::ranges::adjacent_view::size β std::ranges::adjacent_view::size. That's the name, bestie, it's giving βI repeat myself because that's literally the manpage NAME line.β π
β¨ Synopsis β¨
Two overloads, both (since C++23), both constexpr, and both gated by a requires clause. Here's the exact signature tea:
constexpr auto size() requires ranges::sized_range<V>;
(since C++23)
constexpr auto size() const requires ranges::sized_range<const V>;
(since C++23)
Returns the number of elements. Let base_ be the underlying view. Equivalent to:
using SizeType = decltype(ranges::size(base_));
using CommonType = ranges::common_type_t<SizeType, std::size_t>;
auto size = static_cast<CommonType>(ranges::size(base_));
size -= std::min<CommonType>(size, N - 1);
return static_cast<SizeType>(size);
π Parameters π
(none) β she takes zero parameters. Nothing. Nada. Iconic minimalism. π§
π₯ Return value π₯
The number of elements, may be 0 if ranges::size(base_) is less than N. So if the underlying range is too short, bestie can absolutely hand you a zero. No drama, just math. β¨
π Example π
The page says // Run this code, and here's the exact code, no edits, no cap:
#include <ranges>
int main()
{
constexpr static auto v = {1, 2, 3, 4, 5, 6};
constexpr int width1 {4};
constexpr auto view1 {std::views::adjacent<width1>(v)};
static_assert(view1.size() == 3);
static_assert(view1.size() == (v.size() - width1 + 1));
constexpr int width2 {8};
constexpr auto view2 {std::views::adjacent<width2>(v)};
// window is too wide, so view2 has no elements:
static_assert(view2.size() == 0);
}
π¦ See also π¦
ranges::sizeβ returns an integer equal to the size of a range.(C++20),(customization point object).ranges::ssizeβ returns a signed integer equal to the size of a range.(C++20),(customization point object).
That's the whole page, bestie β slay, periodt, and may your size() always be sized. π
xoxo, your C++ bestie π
β source: http://cppreference.com, version/date: 2024.06.10, page: std::ranges..._view::size(3).
π¦ 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