# std::ranges::stride_view<V>::size

> C++ Atlas: `cppatlas.com/w/cpp/ranges/stride_view/size` | Source: https://en.cppreference.com/w/cpp/ranges/stride_view/size | Domain: Ranges | Standards: C++20, C++23

Returns the number of elements.

## Official Specification Summary (cppreference)

```cpp
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 and `stride_` be the stored stride value. Equivalent to:

```cpp
return /*to-unsigned-like*/(/*div-ceil*/(ranges::distance(base_), stride_));
```

### Parameters

(none)

### 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)`.

### Example

```cpp
#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`](https://en.cppreference.com/w/cpp/ranges/size) (C++20): returns an integer equal to the size of a range (customization point object)
- [`ranges::ssize`](https://en.cppreference.com/w/cpp/ranges/ssize) (C++20): returns a signed integer equal to the size of a range (customization point object)

---
Attribution: content from https://en.cppreference.com/w/cpp/ranges/stride_view/size (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.