std::any::has_value
From cppreference.com
| bool has_value() const noexcept; |
(C++17以降) | |
オブジェクトが値を保持しているかどうかをチェックします。
目次 |
[編集] パラメータ
(なし)
[編集] 戻り値
true インスタンスが値を保持している場合、かつその場合に限り。
[編集] 例
このコードを実行
#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); }
[編集] 関連項目
| 内包オブジェクトを破棄する (公開メンバ関数) |