xbot/myirc/include/c_callback.hpp

17 lines
435 B
C++
Raw Normal View History

2023-11-27 18:47:32 -08:00
#pragma once
template <typename> struct CCallback_;
template <typename F, typename R, typename... Ts>
struct CCallback_<R (F::*) (Ts...) const>
{
static R invoke(Ts... args, void* u)
{
return (*reinterpret_cast<F*>(u))(args...);
}
};
2025-01-30 09:28:28 -08:00
/// @brief Wrapper for passing closures through C-style callbacks.
/// @tparam F Type of the closure
2023-11-27 18:47:32 -08:00
template <typename F>
using CCallback = CCallback_<decltype(&F::operator())>;