std::inplace_vector<T,N>::end, std::inplace_vector<T,N>::cend
constexpr iterator end() noexcept; | (1) | (начиная с C++26) |
constexpr const_iterator end() const noexcept; | (2) | (начиная с C++26) |
constexpr const_iterator cend() const noexcept; | (3) | (начиная с C++26) |
Возвращает итератор на элемент, следующий за последним элементом inplace_vector.
Этот элемент служит заполнителем; попытка доступа к нему приводит к неопределённому поведению.
Возвращаемое значение
Итератор на элемент, следующий за последним элементом.
Сложность
Константная.
Пример
#include <algorithm>
#include <cassert>
#include <iostream>
#include <numeric>
#include <string>
#include <inplace_vector>
int main()
{
std::inplace_vector<int, 5> nums{1, 2, 4, 8, 16};
std::inplace_vector<std::string, 3> fruits{"orange", "apple", "raspberry"};
std::inplace_vector<char, 0> empty;
// Print inplace_vector nums.
std::for_each(nums.cbegin(), nums.cend(),
[](const int n) { std::cout << n << ' '; });
std::cout << '\n';
// Sum all integers in the inplace_vector nums, printing only the result.
std::cout << "Sum of nums: "
<< std::accumulate(nums.cbegin(), nums.cend(), 0) << '\n';
// Print the first fruit in the inplace_vector fruits, checking if there is any.
if (!fruits.empty())
std::cout << "First fruit: " << *fruits.cbegin() << '\n';
if (empty.cbegin() == empty.cend())
std::cout << "inplace_vector ‘empty’ is indeed empty.\n";
// Modify the first element in nums.
*nums.begin() = 32;
assert(*nums.cbegin() == 32);
}
Вывод:
1 2 4 8 16 Sum of nums: 31 First fruit: orange inplace_vector ‘empty’ is indeed empty.
См. также
| возвращает итератор на начало (открытая функция-член) |
|
|
(C++11)(C++14) | возвращает итератор на конец контейнера или массива (шаблон функции) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/container/inplace_vector/end