std::optional<T>::end
Aus de.cppreference.net
constexpr iterator end() noexcept;
|
(seit C++26) | |
constexpr const_iterator end() const noexcept;
|
(seit C++26) | |
Gibt einen End-Iterator (past-the-end) zurück. Äquivalent zu return begin() + has_value();.
Rückgabewert
Past-the-end-Iterator
Komplexität
Konstante.
Hinweise
| Feature-Test Makro | Wert | Std | Feature |
|---|---|---|---|
__cpp_lib_optional_range_support
|
202406L
|
(C++26) | Bereichsunterstützung für std::optional |
Beispiel
Diesen Code ausführen
#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()); // Unterstützung für Range-basierte for-Schleifen for (int i : none) std::println("Optional @1 hat einen Wert von {}", i); for (int i : some) std::println("Optional @2 hat einen Wert von {}", i); }
Ausgabe:
Optional @2 hat einen Wert von 42
Siehe auch
|
(C++26)
|
gibt einen Iterator zum Anfang zurück
(öffentliche Elementfunktion) |