std::deque:...deque::cend(3)

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

πŸ’– std::deque::end, std::deque::cend β€” C++ Standard Libary πŸ’–

okay so bestie, this is the std::deque:...deque::cend(3) page from the C++ Standard Libary, and it's all about std::deque::end and std::deque::cend. no cap, it's giving β€œiterator to the end” main character energy. πŸ’…

πŸ’– NAME πŸ’–

std::deque::end,std::deque::cend β€” std::deque::end,std::deque::cend. yes, the NAME really said it twice, and honestly? iconic. πŸŽ€

🌸 Synopsis 🌸

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)

so yeah: overloads (1) and (2) are noexcept since C++11, and overload (3) is cend() const noexcept with (since C++11). slay. ✨

Returns an iterator to the element following the last element of the deque. literally that exact vibe. πŸ¦‹

🚨 warning bestie: this element acts as a placeholder; attempting to access it results in undefined behavior. do not touch it. undefined behavior is not cute. πŸ˜­πŸ’€

there's also a diagram called range-begin-end.svg in the original β€” range-begin-end visual, iykyk. 🌈

πŸŽ€ Parameters πŸŽ€

(none) β€” literally no parameters, bestie. zero. nada. 🫢

✨ Return value ✨

Iterator to the element following the last element. that's the whole return value, periodt. πŸ‘‘

πŸ¦‹ Complexity πŸ¦‹

Constant. yup, constant β€” no drama, no surprises. πŸ’œ

πŸ’… Notes πŸ’…

libc++ backports cend() to C++98 mode. ngl, that's kinda iconic of libc++. πŸ”₯

πŸ”₯ Example πŸ”₯

the page literally says // Run this code, so here's the whole example:

#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <deque>

int main()
{
    std::deque<int> nums{1, 2, 4, 8, 16};
    std::deque<std::string> fruits{"orange", "apple", "raspberry"};
    std::deque<char> empty;

    // Print deque.
    std::for_each(nums.begin(), nums.end(), [](const int n) { std::cout << n << ' '; });
    std::cout << '\n';

    // Sums all integers in the deque nums (if any), printing only the result.
    std::cout << "Sum of nums: "
              << std::accumulate(nums.begin(), nums.end(), 0) << '\n';

    // Prints the first fruit in the deque fruits, checking if there is any.
    if (!fruits.empty())
        std::cout << "First fruit: " << *fruits.begin() << '\n';

    if (empty.begin() == empty.end())
        std::cout << "deque 'empty' is indeed empty.\n";
}

Output:

1 2 4 8 16
Sum of nums: 31
First fruit: orange
deque 'empty' is indeed empty.

ate. no crumbs. πŸ“βœ¨

πŸ‘‘ 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)

that's every token from the See also chunk, bestie β€” even the squished column bits. 🧚


πŸ’– source/version: http://cppreference.com Β· date: 2024.06.10 Β· page: std::deque:...deque::cend(3) πŸ’– byeeee, bestie πŸŽ€

πŸ“¦ where this page comes from