1234567891011121314151617181920212223242526272829303132333435 |
- // callbacks
- // not meant to be read top to bottom, but rather following the function calls, starting from main
- #include <functional> // to demo std::function style callbacks
- class handle_t
- {
- public:
- ~handle_t(); // cancels the request
- };
- class result_t; // what we want
- class error_t; // what may happen instead
- handle_t request_c(void(*)(void*, result_t), void(*)(void*, error_t), void*) { return {}; }
- handle_t request_f(std::function<void(result_t)>, std::function<void(error_t)>) { return {}; }
- template <typename Callback>
- // insert sfinae or require for callback, accepting either result or error
- handle_t request_m(Callback) { return {}; }
- void on_completion(result_t);
- void on_completion(error_t);
- int main(int argc, char const* argv[])
- {
- auto handle = request_m([](auto result)
- {
- on_completion(result);
- });
- return 0;
- }
|