Or simply use an 'inline constexpr lambda':
inline constexpr add = [] <typename T> (T1 lhs, T2 rhs) { return lhs + rhs; };
// Robin
On 2/27/25 03:38, Jack O'Donohue via Std-Proposals wrote:
> I noticed that unlike when initializing function pointers, std::function
> (and copyable_function, etc.) can't select the right overload of a
> function when it is initialized. For example,
The core problem is not std::function, but rather overloaded functions.
The same problem occurs when we pass an overloaded function as argument
to another function, such as std::apply.
A solution to this problem is to wrap the overloaded function as a
function object (similar to std::plus etc.)
inline constexpr struct {
template <typename... Args>
auto operator()(Args&&... args) const {
return add(forward<Args>(args)...);
}
} my_add{};
It is possible to create macros for this, such as
https://www.boost.org/doc/libs/release/libs/hof/doc/html/include/boost/hof/lift.html
Hopefully reflection will enable us to lift overloaded functions
directly.
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals