C++ Logo

std-proposals

Advanced search

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

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Sat, 3 May 2025 19:10:37 +0100
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).

Received on 2025-05-03 18:10:48