std::ranges..._view::size(3)
β¨ NAME β¨
okay bestie, welcome to std::ranges..._view::size(3) from the C++ Standard Libary manual (that's the header's spelling, not mine π) β today's main character is std::ranges::stride_view::size, aka the size member of std::ranges::stride_view, and she has two constexpr overloads and a whole lot of math energy β¨
π SYNOPSIS π
constexpr auto size() requires ranges::sized_range<V>;β since C++23 π«Άconstexpr auto size() const requires ranges::sized_range<const V>;β since C++23 π«Ά
She returns the number of elements, periodt.
Let base_ be the underlying view and stride_ be the stored stride value. Equivalent to:
return __to_unsigned_like(__div_ceil(ranges::distance(base_),
stride_));
πΈ PARAMETERS πΈ
Nope, none. Not a single parameter. She's low-maintenance like that π
π RETURN VALUE π
The number of elements. The returned value is calculated as if by expression:
(ranges::size(base_) / stride_) + ((ranges::size(base_) % stride_ ? 1 : 0).
copying that exactly, bestie π«Ά
π§ EXAMPLE π§
// Run this code
#include <forward_list>
#include <ranges>
int main()
{
namespace vs = std::views;
constexpr static auto v = {1, 2, 3, 4, 5};
static_assert
(
vs::stride(v, 1).size() == 5 and
vs::stride(v, 2).size() == 3 and
vs::stride(v, 3).size() == 2 and
vs::stride(v, 4).size() == 2 and
vs::stride(v, 5).size() == 1 and
vs::stride(v, 6).size() == 1
);
std::forward_list list{v};
// auto s = vs::stride(list, 2).size(); // Error: not a sized_range
}
π¦ 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 tea: source http://cppreference.com, dated 2024.06.10, and this iconic page is std::ranges..._view::size(3). byeee π
π
π¦ 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