std::ranges...erface::size(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

✨ std::ranges::view_interface::size ✨

okay bestie, this is the C++ Standard Libary manual page for std::ranges::view_interface::size, and we’re gonna make it make sense. no cap. 🫢

πŸŽ€ NAME πŸŽ€

std::ranges::view_interface::size β€” std::ranges::view_interface::size

🌸 Synopsis 🌸

here’s the exact signature energy, bestie β€” two overloads, both (since C++20), and yes the formatting is giving β€œmanpage chic” πŸ˜­πŸ’…

          constexpr auto size() requires ranges::forward_range<D> &&

              std::sized_sentinel_for<ranges::sentinel_t<D>,
       (1) (since C++20)

                                      ranges::iterator_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>,

                                      ranges::iterator_t<const D>>;

the default implementation of the size() member function gets the size of the range by calculating the difference between the sentinel and the beginning iterator. iconic behavior, honestly. ✨

  1. let derived be static_cast<D&>(*this). Equivalent to return /*to-unsigned-like*/(ranges::end(derived) - ranges::begin(derived));, where the exposition-only function template to-unsigned-like performs the explicit cast from the argument type to its corresponding unsigned type.
  2. same as (1), except that derived is static_cast<const D&>(*this).

🫢 Parameters 🫢

(none) β€” literally none. no args, no stress. 😌

πŸ’– Return value πŸ’–

the difference between the sentinel and the beginning iterator of the value of the derived type, converted to its corresponding unsigned type. slay. πŸ‘‘

🧚 Notes 🧚

following derived types may use the default implementation of size():

  • std::ranges::drop_while_view

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

πŸ’€ Defect reports πŸ’€

the following behavior-changing defect reports were applied retroactively to previously published C++ standards:

  • LWG 3646 β€” applied to C++20; as published: the default implementations of size functions returned a signed type; correct behavior: they return unsigned type.

πŸ”₯ See also πŸ”₯

  • size (C++17) β€” returns the size of a container or array (function template)
  • ssize (C++20) β€” returns the size of a container or array (function template)
  • ranges::size (C++20) β€” returns an integer equal to the size of a range (customization point object)
  • ranges::ssize (C++20) β€” returns a signed integer equal to the size of a range (customization point object)

source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::ranges...erface::size(3) β€” bye bestie, go get that unsigned type πŸ’…βœ¨

πŸ“¦ where this page comes from