std::ranges...t_view::end(3)

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

πŸŽ€ std::ranges...t_view::end(3) πŸŽ€

okay bestie, welcome to the C++ Standard Libary corner of the internet β€” this page is all about std::ranges::split_view::end, and we’re gonna make it make sense πŸ’…βœ¨

🌸 NAME 🌸

std::ranges::split_view::end - std::ranges::split_view::end

πŸ¦‹ Synopsis πŸ¦‹

constexpr auto end() const;  (since C++20)

This one returns an iterator or a sentinel representing the end of the resulting subrange. It’s giving range-terminator realness, no cap 😌

Equivalent to:

constexpr auto end()
{
    if constexpr (ranges::common_range<V>)
        return /*iterator*/{*this, ranges::end(base_), {}};
    else
        return /*sentinel*/{*this};
}

πŸ’– Parameters πŸ’–

(none)

Literally nothing to pass here, bestie 🫢

✨ Return value ✨

An iterator or a sentinel. That’s the whole vibe check πŸ¦‹

πŸ“ Example πŸ“

// Run this code

#include <iostream>
#include <ranges>
#include <string_view>

int main()
{
    constexpr std::string_view keywords{"bitand bitor bool break"};
    std::ranges::split_view kw{keywords, ' '};
    const auto count = std::ranges::distance(kw.begin(), kw.end());
    std::cout << "Words count: " << count << '\n';
}

Output:

Words count: 4

And yes, the example prints exactly that β€” four words, slay πŸŽ€

🌈 See also 🌈

  • begin β€” returns an iterator to the beginning (C++20) (public member function)
  • end β€” returns an iterator or a sentinel to the end (C++20) (public member function of std::ranges::lazy_split_view<V,Pattern>)
  • ranges::end β€” returns a sentinel indicating the end of a range (C++20) (customization point object)

These are your go-to see-also besties, iykyk πŸ‘‘


std::ranges...t_view::end(3) out β€” source/version: http://cppreference.com, date: 2024.06.10. catch you later, bestie πŸ«ΆπŸ’–

πŸ“¦ where this page comes from