It's a type alias. It makes curl_write the type of a pointer to functions that return size_t and takes arguments char*, size_t, size_t, std::string*. However it is terrible code because it's C code, in actual C++ you'd at the very least be using using and never typedef but ideally properly put that entire thing into a concept and use templates.
Luckily the curl api has a void* data param, so we can actually wrap any callable into a type that exposes a std::function like interface with two methods, one to get the callback that calls the callable and one to get the volid *. The really nasty ones are the ones without that data param
Thanks, nice writeup. I have a struct I wrote that just does it for me, it's common enough. I haven't explorer the case of doing actual thunking when there is no void*data pointer.
Both of these are hard to do, yeah. Well this one isn't but too distracting from the code at hand. Not sure if a full library that does things to make C-apis less errorprone, or a core thing.
4
u/daedalususedperl Jan 30 '23
I'm confused about this line, what does it do?