Skip to content

Instantly share code, notes, and snippets.

@heapwolf
Created August 29, 2014 14:50
Show Gist options
  • Save heapwolf/3e29d13760b05164b327 to your computer and use it in GitHub Desktop.
Save heapwolf/3e29d13760b05164b327 to your computer and use it in GitHub Desktop.

// // 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;
                            ^ ~~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment