std::unique_ptr<T,Deleter>::operator bool
提供: cppreference.com
<tbody>
</tbody>
explicit operator bool() const noexcept; |
(C++11以上) | |
*this がオブジェクトを所有しているかどうか、すなわち get() != nullptr かどうかを調べます。
引数
(なし)
戻り値
*this がオブジェクトを所有していれば true、そうでなければ false。
例
Run this code
#include <iostream>
#include <memory>
int main()
{
std::unique_ptr<int> ptr(new int(42));
if (ptr) std::cout << "before reset, ptr is: " << *ptr << '\n';
ptr.reset();
if (ptr) std::cout << "after reset, ptr is: " << *ptr << '\n';
}
出力:
before reset, ptr is: 42
関連項目
| 管理対象オブジェクトへのポインタを返します (パブリックメンバ関数) |