std::ranges::view_interface<D>::size
From cppreference.com
< cpp | ranges | view interface
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Ranges library
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++26)(C++26)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)
(C++23)(C++23)
(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)
constexpr auto size() requires ranges::forward_range <D> &&
(1)
(since C++20)
std::sized_sentinel_for <ranges::sentinel_t <D>,
constexpr auto size() const requires ranges::forward_range <const D> &&
(2)
(since C++20)
std::sized_sentinel_for <ranges::sentinel_t <const D>,
The default implementation of size()
member function obtains the size of the range by calculating the difference between the sentinel and the beginning iterator.
Contents
[edit] Return value
1)
to-unsigned-like
(ranges::end (static_cast<D&>(this)) -
ranges::begin (static_cast<D&>(this))).2)
to-unsigned-like
(ranges::end (static_cast<const D&>(this)) -
ranges::begin (static_cast<const D&>(this))).[edit] Notes
Following derived types may use the default implementation of size()
:
Following types are derived from std::ranges::view_interface and do not declare their own size()
member function, but they cannot use the default implementation, because their iterator and sentinel types never satisfy sized_sentinel_for
:
- std::ranges::basic_istream_view
- std::ranges::filter_view
- std::ranges::join_view
- std::ranges::lazy_split_view
- std::ranges::split_view
- std::ranges::take_while_view
[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 3646 | C++20 | the default implementations of size functions returned a signed type
|
they return unsigned type |