std::unique_ptr<T,Deleter>::operator<<
提供: cppreference.com
< cpp | memory | unique ptr
template <class CharT, class Traits, class Y, class D> std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, |
(C++20以上) | |
p
によって管理されているポインタの値を出力ストリーム os
に挿入します。
os << p.get()
と同等です。
このオーバーロードは、os << p.get() が有効な式である場合にのみ、オーバーロード解決に参加します。
目次 |
[編集] 引数
os | - | p を挿入する std::basic_ostream
|
p | - | os に挿入されるポインタ
|
[編集] 戻り値
os
[編集] ノート
std::unique_ptr<Y, D>::pointer が文字型へのポインタ (つまり Y
が char、 char[] または CharT) の場合、これは operator<<
のポインタ自身の値を表示するためのオーバーロードではなく、NULL終端文字列のためのオーバーロードを呼ぶことになります (ポインタが実際にはそのような文字列を指していない場合、未定義動作を発生します)。
[編集] 例
Run this code
#include <iostream> #include <memory> class Foo {}; int main() { auto p = std::make_unique<Foo>(); std::cout << p << '\n'; std::cout << p.get() << '\n'; }
出力例:
0x6d9028 0x6d9028
[編集] 関連項目
管理対象オブジェクトへのポインタを返します (パブリックメンバ関数) |