std::unique_ptr<T,Deleter>::operator<<
From cppreference.com
< cpp | memory | unique ptr
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Memory management library
(exposition only*)
(C++11)
(C++23)
(C++11)
(C++17)
(C++11)
(C++11)
(C++20)
(C++20)
(C++17)
(C++11)
(C++17)
(C++20)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
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)
(C++11)
(C++11)
(C++17)
(C++20)
(C++17)
(C++11)
(C++11)
(C++11)
(until C++17*)
(C++11)
(C++17)
(C++26)
(C++26)
(C++11)
(C++11)
(C++11)
(C++23)
(C++23)
(C++11)
(C++20)
(C++11)
(C++11)
(C++20)
(C++26)
std::unique_ptr
(C++14)(C++20)
(until C++20)(C++20)
operator<<
(C++20)
template< class CharT, class Traits, class Y, class D >
(since C++20)
std::basic_ostream <CharT, Traits>& operator<<( std::basic_ostream <CharT, Traits>& os,
Inserts the value of the pointer managed by p into the output stream os.
Equivalent to os << p.get().
This overload participates in overload resolution only if os << p.get() is a valid expression.
Contents
[edit] Parameters
os
-
a std::basic_ostream to insert p into
p
-
the pointer to be inserted into os
[edit] Return value
os
[edit] Notes
If std::unique_ptr <Y, D>::pointer is a pointer to a character type (e.g., when Y
is char([]) or CharT([])), this may end up calling the overloads of operator<<
for null-terminated character strings (causing undefined behavior if the pointer does not in fact point to such a string), rather than the overload for printing the value of the pointer itself.
[edit] Example
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'; }
Possible output:
0x6d9028 0x6d9028