Spec-Zone.ru › C++

std::multiset<Key,Compare,Allocator>::end, std::multiset<Key,Compare,Allocator>::cend

(1)
iterator end();
(до C++11)
iterator end() noexcept;
(с C++11)
(2)
const_iterator end() const;
(до C++11)
const_iterator end() const noexcept;
(с C++11)
const_iterator cend() const noexcept;
(3) (с C++11)

Возвращает итератор на элемент, следующий за последним элементом multiset.

Этот элемент используется как плейсхолдер; попытка доступа к нему приводит к неопределённому поведению.

range-begin-end.svg

Параметры

(нет)

Значение, возвращаемое функцией

Итератор на элемент, следующий за последним элементом.

Сложность

Постоянная.

Примечания

Так как и iterator , и const_iterator являются константными итераторами (и, возможно, имеют один и тот же тип), изменить элементы контейнера через итератор, возвращённый любой из этих функций-членов, невозможно.

Пример

#include <iostream>
#include <iterator>
#include <set>
#include <string>
 
int main()
{
    const std::multiset<std::string> words =
    {
        "some", "not", "sorted", "words",
        "will", "come", "out", "sorted",
    };
 
    for (auto it = words.begin(); it != words.end(); )
    {
        auto count = words.count(*it);
        std::cout << *it << ":\t" << count << '\n';
        std::advance(it, count); // all count elements have equivalent keys
    }
}

Вывод:

come:        1
not:        1
out:        1
some:        1
sorted:        2
will:        1
words:        1

См. также

begincbegin
(C++11)
возвращает итератор на начало
(публичная функция-член)
endcend
(C++11)(C++14)
возвращает итератор на конец контейнера или массива
(шаблон функции)

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/container/multiset/end

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API