Namespaces
Variants

std::unique_ptr<T,Deleter>:: operator<<

From cppreference.net
Memory management library
( exposition only* )
Allocators
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
( until C++20* )
( until C++20* )
( until C++20* )

Garbage collector support (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
template < class CharT, class Traits, class Y, class D >

std:: basic_ostream < CharT, Traits > & operator << ( std:: basic_ostream < CharT, Traits > & os,

const std:: unique_ptr < Y, D > & p ) ;
(C++20以降)

p が管理するポインタの値を出力ストリーム os に挿入します。

os << p. get ( ) と同等です。

このオーバーロードは、以下の条件を満たす場合にのみオーバーロード解決に参加します: os << p. get ( ) が有効な式である場合。

目次

パラメータ

os - a std::basic_ostream to insert p into
p - the pointer to be inserted into os

戻り値

os

注記

std:: unique_ptr < Y, D > :: pointer が文字型へのポインタである場合(例えば Y char ( [ ] ) または CharT ( [ ] ) の場合)、これは ヌル終端文字列用の operator<< オーバーロード を呼び出す可能性があります(実際にそのポインタがそのような文字列を指していない場合、未定義動作を引き起こします)。その結果、 ポインタ自体の値を出力するオーバーロード ではなくなります。

#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

関連項目

管理対象オブジェクトへのポインタを返す
(公開メンバ関数)