- memory[meta header]
- std[meta namespace]
- shared_ptr[meta class]
- function[meta id-type]
- cpp11[meta cpp]
explicit operator bool() const noexcept;
有効なリソースを所有しているかを判定する。
get() != nullptr
- get()[link get.md]
#include <iostream>
#include <memory>
int main()
{
std::shared_ptr<int> p(new int(3));
if (p) {
std::cout << "p has resource" << std::endl;
}
else {
std::cout << "p doesn't have resource" << std::endl;
}
}
p has resource
- C++11
- GCC: 4.4.7
- Clang libc++, C++11 mode: 3.0
- ICC: ?
- Visual C++: 2008 (TR1), 2010, 2012, 2013
- 2012までは、コンパイラが
explicit operator bool
に対応していないため、不透明な型へのポインタ型への変換演算子関数として実装されている。
- 2012までは、コンパイラが