std::multimap<Key,T,Compare,Allocator>:: end, std::multimap<Key,T,Compare,Allocator>:: cend
From cppreference.net
|
iterator end
(
)
;
|
(1) |
(自 C++11 起为 noexcept)
(自 C++26 起为 constexpr) |
|
const_iterator end
(
)
const
;
|
(2) |
(自 C++11 起为 noexcept)
(自 C++26 起为 constexpr) |
|
const_iterator cend
(
)
const
noexcept
;
|
(3) |
(自 C++11 起)
(自 C++26 起为 constexpr) |
返回指向 * this 最后一个元素之后位置的迭代器。
此返回的迭代器仅作为哨兵使用。不保证其具有 可解引用性 。
目录 |
返回值
指向最后一个元素之后的迭代器。
复杂度
常量。
注释
libc++ 向后移植
cend()
至 C++98 模式。
示例
运行此代码
#include <algorithm> #include <cassert> #include <cstddef> #include <iostream> #include <map> #include <string> int main() { auto show_node = [](const auto& node, char ending = '\n') { std::cout << "{ " << node.first << ", " << node.second << " }" << ending; }; std::multimap<std::size_t, std::string> mmap; assert(mmap.begin() == mmap.end()); // 正常 assert(mmap.cbegin() == mmap.cend()); // 正常 mmap.insert({ sizeof(long), "LONG" }); show_node(*(mmap.cbegin())); assert(mmap.begin() != mmap.end()); // 正常 assert(mmap.cbegin() != mmap.cend()); // 正常 mmap.begin()->second = "long"; show_node(*(mmap.cbegin())); mmap.insert({ sizeof(int), "int" }); show_node(*mmap.cbegin()); mmap.insert({ sizeof(short), "short" }); show_node(*mmap.cbegin()); mmap.insert({ sizeof(char), "char" }); show_node(*mmap.cbegin()); mmap.insert({{ sizeof(float), "float" }, { sizeof(double), "double"}}); std::cout << "mmap = { "; std::for_each(mmap.cbegin(), mmap.cend(), [&](const auto& n) { show_node(n, ' '); }); std::cout << "};\n"; }
可能的输出:
{ 8, LONG }
{ 8, long }
{ 4, int }
{ 2, short }
{ 1, char }
mmap = { { 1, char } { 2, short } { 4, int } { 4, float } { 8, long } { 8, double } };
参见
|
(C++11)
|
返回指向起始位置的迭代器
(公开成员函数) |
|
(C++11)
(C++14)
|
返回指向容器或数组末尾的迭代器
(函数模板) |