std::deque:...deque::cend(3)
π 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 beginningcbeginβ (public member function) (C++11)endcendβ 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
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms