std::optional<T>:: end
From cppreference.net
C++
Utilities library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::optional
| Member functions | ||||
| Observers | ||||
| Iterators | ||||
|
(C++26)
|
||||
|
optional::end
(C++26)
|
||||
| Monadic operations | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
| Modifiers | ||||
| Non-member functions | ||||
| Deduction guides | ||||
| Helper classes | ||||
| Helper objects | ||||
|
constexpr
iterator end
(
)
noexcept
;
|
(seit C++26) | |
|
constexpr
const_iterator end
(
)
const
noexcept
;
|
(seit C++26) | |
Gibt einen Past-the-End-Iterator zurück. Entspricht return begin ( ) + has_value ( ) ; .
Inhaltsverzeichnis |
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) |