30 std::unique_ptr<T> value;
33 static std::vector<Slot>& thread_slots()
35 static thread_local std::vector<Slot> slots;
39 std::uint64_t m_id = detail::ets_id_counter().fetch_add(1, std::memory_order_relaxed);
40 std::function<T()> m_factory;
44 : m_factory([]() {
return T(); })
49 typename = std::enable_if_t<!std::is_same_v<std::decay_t<U>, enumerable_thread_specific>>>
50 explicit enumerable_thread_specific(U&& init)
51 : m_factory([captured = T(std::forward<U>(init))]() {
return captured; })
54 enumerable_thread_specific(
const enumerable_thread_specific&) =
delete;
55 enumerable_thread_specific& operator=(
const enumerable_thread_specific&) =
delete;
56 enumerable_thread_specific(enumerable_thread_specific&&) =
delete;
57 enumerable_thread_specific& operator=(enumerable_thread_specific&&) =
delete;
59 ~enumerable_thread_specific()
63 auto& slots = thread_slots();
68 [
this](
const Slot& s) { return s.id == m_id; }),
74 auto& slots = thread_slots();
75 for (
auto& s : slots) {
81 slots.push_back(Slot{m_id, std::make_unique<T>(m_factory())});
82 return *slots.back().value;