This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++20 status.

### 2948. `unique_ptr` does not define `operator<<` for stream output

Section: 20.11.1 [unique.ptr] Status: C++20 Submitter: Peter Dimov Opened: 2017-03-19 Last modified: 2021-02-25

Priority: 0

View all other issues in [unique.ptr].

View all issues with C++20 status.

Discussion:

`shared_ptr` does define `operator<<`, and `unique_ptr` should too, for consistency and usability reasons.

[2017-07 Toronto Wed Issue Prioritization]

Priority 0; move to Ready

Proposed resolution:

This wording is relative to N4659.

1. Change 20.10.2 [memory.syn], header `<memory>` synopsis, as indicated:

   >     namespace std {
   >       […]

   >       // 20.11.1 [unique.ptr], class template unique_ptr
   >       […]
   >       template <class T, class D>
   >       bool operator>=(nullptr_t, const unique_ptr<T, D>& y);

   >       template<class E, class T, class Y, class D>
   >       basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, const unique_ptr<Y, D>& p);
   >       […]
   >     }

2. Change 20.11.1 [unique.ptr], class template `unique_ptr` synopsis, as indicated:

   >     namespace std {
   >       […]
   >       template <class T, class D>
   >       bool operator>=(nullptr_t, const unique_ptr<T, D>& y);

   >       template<class E, class T, class Y, class D>
   >       basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, const unique_ptr<Y, D>& p);
   >     }

3. Add a new subclause following subclause 20.11.1.6 [unique.ptr.special] as indicated:

   > 23.11.1.?? `unique_ptr` I/O [unique.ptr.io]

   >     template<class E, class T, class Y, class D>
   >       basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, const unique_ptr<Y, D>& p);

   > > -?- Effects: Equivalent to `os << p.get();`

   > > -?- Returns: `os`.

   > > -?- Remarks: This function shall not participate in overload resolution unless `os << p.get()` is a valid expression.