This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.
function_ref should provide result_typeSection: 22.10.17.6.2 [func.wrap.ref.class] Status: New Submitter: Hewill Kang Opened: 2025-09-12 Last modified: 2025-10-22
Priority: 3
View all issues with New status.
Discussion:
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.
[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.
[2025-10-22; Reflector poll.]
Set priority to 3 after reflector poll.
Alternative (with incoming paper targeting LEWG) of deprecating
result_type in existing wrappers was suggested.
Proposed resolution:
This wording is relative to N5014.
Modify 22.10.17.6.2 [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;
// 22.10.17.6.3 [func.wrap.ref.ctor], constructors and assignment operators
template<class F> function_ref(F*) noexcept;
[…]
};
}