#pragma once #include "function_detail.h" #include "spin_mutex.h" #include #include namespace fastsignals::detail { class signal_impl { public: uint64_t add(packed_function fn); void remove(uint64_t id) noexcept; void remove_all() noexcept; size_t count() const noexcept; template Result invoke(Args... args) const { packed_function slot; size_t slotIndex = 0; uint64_t slotId = 1; if constexpr (std::is_same_v) { while (get_next_slot(slot, slotIndex, slotId)) { slot.get()(std::forward(args)...); } } else { Combiner combiner; while (get_next_slot(slot, slotIndex, slotId)) { combiner(slot.get()(std::forward(args)...)); } return combiner.get_value(); } } private: bool get_next_slot(packed_function& slot, size_t& expectedIndex, uint64_t& nextId) const; mutable spin_mutex m_mutex; std::vector m_functions; std::vector m_ids; uint64_t m_nextId = 1; }; using signal_impl_ptr = std::shared_ptr; using signal_impl_weak_ptr = std::weak_ptr; } // namespace fastsignals::detail