#pragma once #include "function_detail.h" namespace fastsignals { // Derive your class from not_directly_callable to prevent function from wrapping it using its template constructor // Useful if your class provides custom operator for casting to function struct not_directly_callable { }; template using enable_if_callable_t = typename std::enable_if_t< !std::is_same_v, Function> && !std::is_base_of_v> && std::is_same_v, Return>>; template class function; // Compact function class - causes minimal code bloat when compiled. // Replaces std::function in this library. template class function { public: function() = default; function(const function& other) = default; function(function&& other) noexcept = default; function& operator=(const function& other) = default; function& operator=(function&& other) noexcept = default; template , Return, Arguments...>> function(Fn&& function) noexcept(detail::is_noexcept_packed_function_init) { m_packed.init(std::forward(function)); } Return operator()(Arguments&&... args) const { auto& proxy = m_packed.get(); return proxy(std::forward(args)...); } detail::packed_function release() noexcept { return std::move(m_packed); } private: detail::packed_function m_packed; }; } // namespace fastsignals