std::flat_set::end,(3)

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

🌸 NAME β€” std::flat_set::end from the C++ Standard Libary manual 🌸

okay so bestie, welcome to std::flat_set::end, πŸ’– The NAME line is literally std::flat_set::end, β€” std::flat_set::end, (trailing comma included, we respect the chaos). This is the C++ Standard Library page for it, and yes the original header spells the manual C++ Standard Libary β€” iconic typo, no cap.

πŸŽ€ Synopsis πŸŽ€

Three overloads, all since C++23:

iterator end() noexcept;              (1) (since C++23)
const_iterator end() const noexcept;  (2) (since C++23)
const_iterator cend() const noexcept; (3) (since C++23)

It returns an iterator to the element following the last element of the flat_set. That element is a placeholder, bestie β€” attempting to access it results in undefined behavior, so do not touch it 😭.

There’s also a diagram placeholder in the original here: range-begin-end.svg πŸ–ΌοΈ.

🌈 Parameters 🌈

(none) β€” literally zero parameters. The void is serving. ✨

πŸ’– Return value πŸ’–

Iterator to the element following the last element. That’s it, that’s the tea β˜•.

⚑ Complexity ⚑

Constant. Not linear, not spicy, just constant. periodt. πŸ’…

🧠 Notes 🧠

Because both iterator and const_iterator are constant iterators (and may in fact be the same type), it is not possible to mutate the elements of the container through an iterator returned by any of these member functions.

So no sneaky editing through end() or cend() β€” the vibes are read-only, fr fr. 🫢

πŸ“ Example πŸ“

// Run this code β€” literally go run it:

#include <algorithm>
#include <flat_set>
#include <iostream>

int main()
{
    std::flat_set<int> set{3, 1, 4, 1, 5, 9, 2, 6, 5};
    std::for_each(set.cbegin(), set.cend(), [](int x)
    {
        std::cout << x << ' ';
    });
    std::cout << '\n';
}

🌟 Output 🌟

1 2 3 4 5 6 9

πŸ‘€ See also πŸ‘€

  • begin β€” returns an iterator to the beginning
  • cbegin β€” (public member function)
  • end
  • cend β€” returns an iterator to the end of a container or array
  • (C++11) β€” (function template)
  • (C++14)

xoxo, your Unix bestie πŸ’… β€” source: http://cppreference.com, version/date: 2024.06.10, page: std::flat_set::end,(3) 🫢

πŸ“¦ where this page comes from