Namespaces
Variants

std::optional<T>::end

Aus de.cppreference.net
 
 
Hilfsbibliothek
Sprachunterstützung
Typunterstützung (Basistypen, RTTI)
Bibliotheks-Feature-Test-Makros (C++20)
Programmhilfsmittel
Variadische Funktionen
Koroutinen-Unterstützung (C++20)
Vertragsunterstützung (C++26)
Drei-Wege-Vergleich
(C++20)
(C++20)(C++20)(C++20)    
(C++20)(C++20)(C++20)

Allgemeine Hilfsmittel
Relationsoperatoren (veraltet in C++20)
Ganzzahl-Vergleichsfunktionen
(C++20)(C++20)(C++20)    
(C++20)
Swap und Typoperationen
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Allgemeine Vokabular-Typen
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)



 
 
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

#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)