|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
| Modifiers | ||||
| Observers | ||||
| Non-member functions | ||||
(C++14)(C++20) | ||||
(until C++20)(C++20) | ||||
operator<< (C++20) | ||||
| Helper classes | ||||
template<class CharT,class Traits,class Y,class D> std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, | (since C++20) | |
Inserts the value of the pointer managed byp into the output streamos.
Equivalent toos<< p.get().
This overload participates in overload resolution only ifos<< p.get() is a valid expression.
Contents |
| os | - | astd::basic_ostream to insertp into |
| p | - | the pointer to be inserted intoos |
os
Ifstd::unique_ptr<Y, D>::pointer is a pointer to a character type (e.g., whenY ischar([]) orCharT([])), this may end up calling theoverloads ofoperator<< for null-terminated character strings (causing undefined behavior if the pointer does not in fact point to such a string), rather thanthe overload for printing the value of the pointer itself.
#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:
0x6d90280x6d9028
| returns a pointer to the managed object (public member function)[edit] |