Title
`function_ref` should provide `result_type`
Status
new
Section
[func.wrap.ref.class]
Submitter
Hewill Kang

Created on 2025-09-12.00:00:00 last changed 1 week ago

Messages

Date: 2025-10-04.09:54:58

Proposed resolution:

This wording is relative to N5014.

  1. Modify [func.wrap.ref.class] as indicated:

    namespace std {
      template<class R, class... ArgTypes>
      class function_ref<R(ArgTypes...) cv noexcept(noex)> {
      public:
        using result_type = R;
    
        // [func.wrap.ref.ctor], constructors and assignment operators
        template<class F> function_ref(F*) noexcept;
        […]
      };
    
    }
    
Date: 2025-10-15.00:00:00

[ 2025-10-03; Hewill comments ]

Additionally, given that some third-party implementations also provide a mechanism for extracting the return type, for example, `type_safe::function_ref` provides a public member type alias return_type, and `llvm::function_ref` can work with llvm::function_traits to obtain the return type, providing such a member type alias for `std::function_ref` meets user potential demands.

Date: 2025-09-12.00:00:00

Currently, `function`, `move_only_function`, and `copyable_function` all have a type member `result_type`, but `function_ref` does not:

static_assert(is_same_v<          function    <int(int)>::result_type, int>);
static_assert(is_same_v<move_only_function    <int(int)>::result_type, int>);
static_assert(is_same_v< copyable_function    <int(int)>::result_type, int>);
static_assert(is_same_v<          function_ref<int(int)>::result_type, int>); // error

It seems worthwhile to also provide it for the latter, as it is consistent with the other wrappers and allows the user to easily extract the return type.

History
Date User Action Args
2025-10-04 09:54:58adminsetmessages: + msg15107
2025-09-19 17:26:49adminsetmessages: + msg15063
2025-09-12 00:00:00admincreate