std::array:...array::cend(3)
πΈ NAME πΈ
std::array::end, std::array::cend β std::array::end,std::array::cend
okay bestie, welcome to the C++ Standard Libary page for std::array::end and std::array::cend β thatβs the std::array:...array::cend(3) title, ily π. This is the one about the iterator that points one past the last element, and itβs lowkey iconic.
β¨ Synopsis β¨
iterator end() noexcept; (1) (since C++11)
(constexpr since C++17)
const_iterator end() const noexcept; (2) (since C++11)
(constexpr since C++17)
const_iterator cend() const noexcept; (3) (since C++11)
(constexpr since C++17)
Returns an iterator to the element following the last element of the array.
This element acts as a placeholder; attempting to access it results in undefined behavior π.
Also, the page has a diagram reference: range-begin-end.svg πΌοΈ.
π Parameters π
(none) β literally no parameters, bestie π«Ά.
π Return value π
Iterator to the element following the last element.
π¦ Complexity π¦
Constant.
π Example π
run this code:
// Run this code
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
int main()
{
std::cout << std::boolalpha;
std::array<int, 0> empty;
std::cout << "1) "
<< (empty.begin() == empty.end()) << ' ' // true
<< (empty.cbegin() == empty.cend()) << '\n'; // true
// *(empty.begin()) = 42; // => undefined behavior at run-time
std::array<int, 4> numbers{5, 2, 3, 4};
std::cout << "2) "
<< (numbers.begin() == numbers.end()) << ' ' // false
<< (numbers.cbegin() == numbers.cend()) << '\n' // false
<< "3) "
<< *(numbers.begin()) << ' ' // 5
<< *(numbers.cbegin()) << '\n'; // 5
*numbers.begin() = 1;
std::cout << "4) " << *(numbers.begin()) << '\n'; // 1
// *(numbers.cbegin()) = 42; // compile-time error:
// read-only variable is not
assignable
// print out all elements
std::cout << "5) ";
std::for_each(numbers.cbegin(), numbers.cend(), [](int x)
{
std::cout << x << ' ';
});
std::cout << '\n';
constexpr std::array constants{'A', 'B', 'C'};
static_assert(constants.begin() != constants.end()); // OK
static_assert(constants.cbegin() != constants.cend()); // OK
static_assert(*constants.begin() == 'A'); // OK
static_assert(*constants.cbegin() == 'A'); // OK
// *constants.begin() = 'Z'; // compile-time error:
// read-only variable is not
assignable
}
Output:
1) true true
2) false false
3) 5 5
4) 1
5) 1 2 3 4
π See also π
beginβ returns an iterator to the beginningcbeginβ (public member function)endcendβ returns an iterator to the end of a container or array(C++11)β (function template)(C++14)
shoutout to cppreference.com for the source, and the date is 2024.06.10, on this std::array:...array::cend(3) page β bye bestie, stay iterator-pilled π
β¨
π¦ 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