Namensräume
Varianten
Aktionen

std::optional<T>::end

Von cppreference.com
< cpp‎ | utility‎ | optional
 
 
Dienstprogramm-Bibliotheken
Sprachunterstützung
Typunterstützung (Basistypen, RTTI)
Bibliotheks-Feature-Test-Makros (C++20)
Programm-Dienstprogramme
Variadische Funktionen
Coroutine-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
Relationale Operatoren (in C++20 veraltet)
 
 
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();.

range-begin-end.svg

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

#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) [bearbeiten]