// // since a lambda with capture doesn't work as a function pointer, we should be able to // make a static cast to a function with the expected signature and return type, then // use that to emulate the expected c type callback function //
auto cb = [&](http_parser* parser, const char* at, size_t length) {
return 0;
};
auto on_body = static_cast
<std::function<int (http_parser* parser, const char* at, size_t length)>>(cb);
parser_settings.on_body = on_body;
CXX(target) out/Release/obj.target/webserver/webserver.o
../webserver.cc:236:29: error: assigning to 'http_data_cb' (aka 'int (*)(http_parser *, const char *,
size_t)') from incompatible type 'std::__1::function<int (http_parser *, const char *, unsigned long)>'
parser_settings.on_body = on_body;
^ ~~