std::multimap<Key,T,Compare,Allocator>::end, std::multimap<Key,T,Compare,Allocator>::cend
來自 cppreference.com
iterator end(); |
(1) | (C++11 起無異常丟擲) |
const_iterator end() const; |
(2) | (C++11 起無異常丟擲) |
const_iterator cend() const noexcept; |
(3) | (C++11 起) |
返回指向 `multimap` 中最後一個元素之後的元素的迭代器。
此元素充當佔位符;嘗試訪問它將導致未定義行為。
目錄 |
[edit] 返回值
指向最後一個元素之後的迭代器。
[edit] 複雜度
常數時間。
注意
libc++ 將 cend()
反向移植到 C++98 模式。
[edit] 示例
執行此程式碼
#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()); // OK assert(mmap.cbegin() == mmap.cend()); // OK mmap.insert({ sizeof(long), "LONG" }); show_node(*(mmap.cbegin())); assert(mmap.begin() != mmap.end()); // OK assert(mmap.cbegin() != mmap.cend()); // OK 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 } };
[edit] 參見
(C++11 起) |
返回指向起始的迭代器 (public member function) |
(C++11 起)(C++14 起) |
返回指向容器或陣列末尾的迭代器 (函式模板) |