std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>::begin, std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>::cbegin
Von cppreference.com
| iterator begin() noexcept; |
(1) | (seit C++23) |
| const_iterator begin() const noexcept; |
(2) | (seit C++23) |
| const_iterator cbegin() const noexcept; |
(3) | (seit C++23) |
Gibt einen Iterator zum ersten Element der flat_map zurück.
Wenn die flat_map leer ist, ist der zurückgegebene Iterator gleich end().
Inhalt |
[bearbeiten] Rückgabewert
Iterator zum ersten Element.
[bearbeiten] Komplexität
Konstant.
[bearbeiten] Beispiel
Führen Sie diesen Code aus
#include <iostream> #include <flat_map> int main() { std::flat_map<int, double> map{{4, 4.13}, {9, 9.24}, {1, 1.09}}; for (auto it = map.cbegin(); it != map.cend(); ++it) std::cout << '[' << it->first << "] = " << it->second << '\n'; // Unlike std::map's bidirectional iterators, the std::flat_map iterators // are random-access, so they can be used with the operator[]: auto it = map.cbegin(); assert(it[0] == map[1]); assert(it[1] == map[4]); assert(it[2] == map[9]); }
Ausgabe
[1] = 1.09 [4] = 4.13 [9] = 9.24
[bearbeiten] Siehe auch
| gibt einen Iterator zum Ende zurück (public member function) | |
| (C++11)(C++14) |
gibt einen Iterator zum Anfang eines Containers oder Arrays zurück (Funktionsvorlage) |