std::deque:...que::cbegin(3)
π std::deque::begin,std::deque::cbegin π
okay so bestie, you opened the std::deque:...que::cbegin(3) page from the C++ Standard Libary manual, and we're about to make std::deque::begin,std::deque::cbegin make sense fr fr. slay β¨
π NAME π
the name is std::deque::begin,std::deque::cbegin β and yes the page repeats it as std::deque::begin,std::deque::cbegin π
β¨ Synopsis β¨
okay so the synopsis is literally this, don't skip the annotations:
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 deque.
If the deque is empty, the returned iterator will be equal to end().
there's also a lil diagram ref named range-begin-end.svg in the original, cute.
π«Ά Parameters π«Ά
(none) β literally not a single parameter, bestie.
π Return value π
Iterator to the first element. that's it, that's the return value.
π Complexity π
Constant. periodt.
π¦ Notes π¦
libc++ backports cbegin() to C++98 mode. that's the whole note, iconic.
π Example π
the original page has // Run this code right before the snippet, so here's the code exactly:
#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.
π See also π
endβ returns an iterator to the endcendβ(public member function)(C++11)begincbeginβ returns an iterator to the beginning of a container or array(C++11)(function template)(C++14)
π mwah π this page came from http://cppreference.com, dated 2024.06.10, and its page id is std::deque:...que::cbegin(3) β bye bestie, go slay your iterators β¨
π¦ 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