News for hackers. Stuff that matters.
Re:Is C++ fast? by asveikau on Friday January 18, 2019 @03:43PM (#18942873)
I agree with your sentiment but the lambdas do get treated as anonymous classes overloading operator ().
Re:Is C++ fast? by kllrnohj on Friday January 18, 2019 @05:32PM (#18943738)
Not really true. Lambdas can be converted to a class overloading operator() (such as std::function), but they are not inherently that. You can use them as just function pointers, too. Example:

    #include <cstdio>

    void call_func(void(*func)()) {
        func();
    }

    int main(int argc, char* argv[]) {
        // Lambda can be converted to a function pointer
        call_func([]() {
            printf("hello as a function pointer\n");
        });
    }
Re:Is C++ fast? by asveikau on Friday January 18, 2019 @05:54PM (#18943899)
> but they are not inherently that.

I am fairly certain I have had error messages and disassemblies that suggest otherwise. This may however be an implementation detail.

> You can use them as just function pointers, too.

Yes, I know this. It only works when there are no captures. And AFAIK once there are captures you start getting object code that looks a lot like you put those captures into an anonymous class. (When not inlined.)

Re:Is C++ fast? by slavik81 on Friday January 18, 2019 @11:24PM (#18945319)
You can get that sort of behaviour from any class by implementing the conversion operator. I assume that lambda implements `operator(void(*)())` so it is implicitly convertible to a function pointer.