std::optional<T>::end
Von cppreference.com
| constexpr iterator end() noexcept; |
(seit C++26) | |
| constexpr const_iterator end() const noexcept; |
(seit C++26) | |
Gibt einen Iterator zurück, der hinter das Ende zeigt. Entspricht return begin() + has_value();.
Inhalt |
[bearbeiten] Parameter
(keine)
[bearbeiten] Rückgabewert
Iterator hinter dem Ende
[bearbeiten] Komplexität
Konstant.
[bearbeiten] Hinweise
| Feature-Test-Makro | Wert | Std | Feature |
|---|---|---|---|
__cpp_lib_optional_range_support |
202406L |
(C++26) | Bereichsunterstützung für std::optional |
[bearbeiten] Beispiel
Führen Sie diesen Code aus
#include <optional> #include <print> int main() { constexpr std::optional<int> none = std::nullopt; // optional @1 constexpr std::optional<int> some = 42; // optional @2 static_assert(none.begin() == none.end()); static_assert(some.begin() != some.end()); // ranged-for loop support for (int i : none) std::println("Optional @1 has a value of {}", i); for (int i : some) std::println("Optional @2 has a value of {}", i); }
Ausgabe
Optional @2 has a value of 42
[bearbeiten] Siehe auch
| (C++26) |
gibt einen Iterator zum Anfang zurück (member function) |