C++ Logo

std-proposals

Advanced search

Re: [std-proposals] noexcept has gotten a bit hairy -- I want a compiler error

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Sun, 4 May 2025 00:02:40 +0100
On Sat, 3 May 2025, 19:10 Frederick Virchanza Gotham via Std-Proposals, <
std-proposals_at_[hidden]> wrote:

> This is a very premature half-baked idea that popped into my head just
> now, but what if we had an operator that could turn an overloaded
> function into a lambda with multiple overloads of operator()? So for
> example consider the two overloads of 'strchr':
>
> const char* strchr( const char* str, int ch );
> char* strchr( char* str, int ch );
>
> What if we could apply the '_Lambda_overloads' operator to 'strchr' as
> follows:
>
> auto mylambda = _Lambda_overloads( strchr );
>
> and we would end up with the 'mylambda' variable being an object of
> the following type:
>
> class Lambda {
> public:
> static const char* operator()( const char* str, int ch ) {
> return strchr(str,ch); }
> static char* operator()( char* str, int ch ) { return
> strchr(str,ch); }
> };
>
> Would this solve the conundrum of not being able to pass overloaded
> functions as template parameters, for example to functions like
> "std::invoke" or "std::apply"?
>
> There is currently a solution but it resorts to using the preprocessor
> (i.e. the "LIFT" macro).



See p0834 and the older proposals that it refers to.

Received on 2025-05-03 23:02:57