std::basic_string::end,(3)

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

okay bestie, this is std::basic_string::end,(3) from the C++ Standard Libary manual, and it's literally the page for std::basic_string's end/cend situation πŸ’– no cap.

πŸŽ€ NAME πŸŽ€

std::basic_string::end, - std::basic_string::end,

yes, that's the NAME line verbatim, comma chaos and all β€” she's a little quirky but iconic πŸ’…

🌸 Synopsis 🌸

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

Okay so this returns an iterator to the character following the last character of the string. That character acts as a placeholder, and bestie, attempting to access it results in undefined behavior 😭 β€” like, do not mess with the placeholder, fr fr.

The original page also has range-begin-end.svg chilling right here β€” iconic filename moment 🌈.

πŸ™ˆ Parameters πŸ™ˆ

(none) β€” not a single parameter, zero, nada, the void πŸ’€.

⭐ Return value ⭐

Iterator to the character following the last character. That's the whole return value, and it ate πŸ’….

πŸ”₯ Complexity πŸ”₯

Constant. That's it. Constant. periodt ⭐.

πŸ’œ Notes πŸ’œ

libc++ backports cend() to C++98 mode. β€” that's the note, and it's lowkey a C++98 backport moment 🫢.

πŸ’» Example πŸ’»

The original says // Run this code, so here's the code verbatim, bestie:

#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>

int main()
{
    std::string s("Exemparl");
    std::next_permutation(s.begin(), s.end());

    std::string c;
    std::copy(s.cbegin(), s.cend(), std::back_inserter(c));
    std::cout << c << '\n'; // "Exemplar"
}

πŸ“ Output: πŸ“

Exemplar

πŸ¦‹ See also πŸ¦‹

  • begin β€” returns an iterator to the beginning
  • cbegin β€” (public member function) (C++11)
  • end β€” returns an iterator to the end
  • cend β€” (public member function of std::basic_string_view<CharT,Traits>)

mwah πŸ’‹ β€” source/version and date: http://cppreference.com Β· 2024.06.10 🌸

πŸ“¦ where this page comes from