Title
indirect<T> should be convertible to T&
Status
nad
Section
[indirect.obs]
Submitter
Zhihao Yuan

Created on 2025-11-05.00:00:00 last changed 2 weeks ago

Messages

Date: 2026-09-10.14:03:08

Proposed resolution:

This wording is relative to N5014.

  1. Modify [indirect.syn], as indicated:

    namespace std {
      template<class T, class Allocator = allocator<T>>
      class indirect {
      public:
        […]
        // [indirect.obs], observers
        constexpr operator const T& () const & noexcept;
        constexpr operator T& () & noexcept;
        constexpr operator const T&& () const && noexcept;
        constexpr operator T&& () && noexcept;
        constexpr const T& operator*() const & noexcept;
        constexpr T& operator*() & noexcept;
        constexpr const T&& operator*() const && noexcept;
        constexpr T&& operator*() && noexcept;
        constexpr const_pointer operator->() const noexcept;
        constexpr pointer operator->() noexcept;
        […]
    
  2. Modify [indirect.obs], as indicated:

    constexpr operator const T& () const & noexcept;
    constexpr operator T& () & noexcept;
    constexpr const T& operator*() const & noexcept;
    constexpr T& operator*() & noexcept;
    

    -1- Preconditions: `*this` is not valueless.

    -2- Returns: *p.

    constexpr operator const T&& () const && noexcept;
    constexpr operator T&& () && noexcept;
    constexpr const T&& operator*() const && noexcept;
    constexpr T&& operator*() && noexcept;
    

    -3- Preconditions: `*this` is not valueless.

    -4- Returns: std::move(*p).

Date: 2026-08-15.00:00:00

[ 2026-08-27; Reflector poll. Status → Tentatively NAD. ]

This is a design change; LEWG rejected the comment for C++26. LEWG can revisit for C++29 if a paper is submitted.

Date: 2025-11-05.00:00:00
Addresses US 77-140

In addition to serving as a better unique_ptr<T> in Pimpl, indirect<T> can also appear as a drop-in replacement for `T` when `T` may conditionally be an incomplete type. In which case, if indirect<T> is convertible to T&, certain tasks can be done without meta-programming (e.g., returning the object of type `T` or indirect<T> from a function with a return type T&).

History
Date User Action Args
2026-09-10 14:03:08adminsetmessages: + msg16580
2026-09-10 14:03:08adminsetstatus: new -> nad
2025-11-06 16:51:20adminsetmessages: + msg15565
2025-11-05 00:00:00admincreate