std::set::b...set::cbegin(3)

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

πŸ’– NAME πŸ’–

std::set::begin,std::set::cbegin β€” and yes bestie, the NAME literally repeats itself as std::set::begin,std::set::cbegin, iconic behavior. This is page std::set::b...set::cbegin(3) from the C++ Standard Libary manual.


✨ Synopsis ✨

iterator begin();                       (1) (noexcept since C++11)
const_iterator begin() const;           (2) (noexcept since C++11)
const_iterator cbegin() const noexcept; (3) (since C++11)

Returns an iterator to the first element of the set.

If the set is empty, the returned iterator will be equal to end().

There’s also a little visual in the original called range-begin-end.svg β€” it’s giving diagram energy πŸ¦‹.


πŸŽ€ Parameters πŸŽ€

(none) β€” zero arguments, she takes nothing, no cap.


🌸 Return value 🌸

Iterator to the first element.


🧚 Complexity 🧚

Constant.


πŸ’… 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 cbegin() to C++98 mode. cute little backport moment πŸ’œ


πŸ“ 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 πŸ‘‘

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

Source/version/date, bestie: http://cppreference.com Β· 2024.06.10 Β· page std::set::b...set::cbegin(3). Mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from