std::any:: has_value
From cppreference.net
C++
Utilities library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
bool
has_value
(
)
const
noexcept
;
|
(seit C++17) | |
Prüft, ob das Objekt einen Wert enthält.
Inhaltsverzeichnis |
Parameter
(keine)
Rückgabewert
true genau dann, wenn die Instanz einen Wert enthält.
Beispiel
Diesen Code ausführen
#include <any> #include <cassert> #include <string> int main() { std::any a0; assert(a0.has_value() == false); std::any a1 = 42; assert(a1.has_value() == true); assert(std::any_cast<int>(a1) == 42); a1.reset(); assert(a1.has_value() == false); auto a2 = std::make_any<std::string>("Andromeda"); assert(a2.has_value() == true); assert(std::any_cast<std::string&>(a2) == "Andromeda"); a2.reset(); assert(a2.has_value() == false); }
Siehe auch
|
zerstört enthaltenes Objekt
(öffentliche Elementfunktion) |