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

Section: 23.11.1 [unique.ptr] Status: WP Submitter: Peter Dimov Opened: 2017-03-19 Last modified: 2017-11-13

Priority: 0

View all other issues in [unique.ptr].

View all issues with WP 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 23.10.2 [memory.syn], header <memory> synopsis, as indicated:

    namespace std {
      […]
      
      // 23.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 23.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 23.11.1.5 [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.