std::set::e...::set::cend(3)

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

✨ NAME ✨

okay so bestie, welcome to the std::set::end,std::set::cend page from the C++ Standard Libary manual, section 3 β€” and yes, the original header spells it "Libary", I'm just preserving the detail 😭. The name is std::set::end,std::set::cend, and the description is also std::set::end,std::set::cend. It's giving "the page title literally repeats itself and still ate", but every fact is staying right here.

🌸 Synopsis 🌸

these are the three signatures, literally:

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

Returns an iterator to the element following the last element of the set.

This element acts as a placeholder; attempting to access it results in undefined behavior. (Translation: do not dereference it, bestie β€” that's undefined behavior and we don't play like that.)

There's a range-begin-end.svg diagram in the original too β€” cute visual, same energy.

πŸ¦‹ Parameters πŸ¦‹

(none) β€” she takes zero parameters, absolutely no notes.

πŸ’– Return value πŸ’–

Iterator to the element following the last element. That's the whole return value, periodt.

πŸ”₯ Complexity πŸ”₯

Constant. That's it, no extra math homework.

πŸ‘‘ 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.
  • libc++ backports cend() to C++98 mode.

πŸŽ€ Example πŸŽ€

// Run this code

#include <algorithm>
#include <iostream>
#include <set>

int main()
{
    std::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) (C++11)
  • end
  • cend β€” returns an iterator to the end of a container or array (C++11) (function template) (C++14)

muah πŸ’‹ sign-off time: source is http://cppreference.com, date is 2024.06.10, and the page tag is std::set::e...::set::cend(3). bye bestie 🫢

πŸ“¦ where this page comes from