//https://vittorioromeo.info/index/blog/passing_functions_to_functions.html template class function_view; template class function_view final { private: using signature_type = TReturn(void*, TArgs...); void* _ptr; TReturn (*_erased_fn)(void*, TArgs...); public: template {} && !std::is_same, function_view>{}>> function_view(T&& x) noexcept : _ptr{(void*)std::addressof(x)} { _erased_fn = [](void* ptr, TArgs... xs) -> TReturn { return (*reinterpret_cast>(ptr))( std::forward(xs)...); }; } decltype(auto) operator()(TArgs... xs) const noexcept(noexcept(_erased_fn(_ptr, std::forward(xs)...))) { return _erased_fn(_ptr, std::forward(xs)...); } };