diff --git a/test/app/counter.cpp b/test/app/counter.cpp index e763296..ad0d36b 100644 --- a/test/app/counter.cpp +++ b/test/app/counter.cpp @@ -155,6 +155,10 @@ auto counter::obj::get() const -> size_t const& { return m_data; } +auto counter::obj::counts() -> counter& { + return *m_counts; +} + auto counter::obj::get() -> size_t& { if (nullptr != m_counts) { ++m_counts->m_data.m_get; diff --git a/test/app/counter.h b/test/app/counter.h index 15149c9..be0199b 100644 --- a/test/app/counter.h +++ b/test/app/counter.h @@ -61,6 +61,8 @@ class counter { [[nodiscard]] auto get() const -> size_t const&; auto get() -> size_t&; + [[nodiscard]] auto counts() -> counter&; + void swap(obj& other); [[nodiscard]] auto get_for_hash() const -> size_t; diff --git a/test/unit/reentrant.cpp b/test/unit/reentrant.cpp index 70bf038..085ffc7 100644 --- a/test/unit/reentrant.cpp +++ b/test/unit/reentrant.cpp @@ -3,33 +3,42 @@ #include #include -TEST_CASE_MAP("reentrant_destruct", counter::obj, counter::obj) { - auto counts = counter{}; - INFO(counts); +namespace { - auto container = typename map_t::value_container_type{}; +class EraseOnDestruct; - // TODO +using map_t = ankerl::unordered_dense::map>; - for (size_t i = 0; i < 100; ++i) { - container.emplace_back(counter::obj{i, counts}, counter::obj{i, counts}); - container.emplace_back(counter::obj{i, counts}, counter::obj{i, counts}); - } +class EraseOnDestruct { + map_t* m_map; + counter::obj m_counter; + +public: + EraseOnDestruct(map_t& map, size_t i, counter& counts) + : m_map(&map) + , m_counter(i, counts) {} - for (size_t i = 0; i < 10; ++i) { - container.emplace_back(counter::obj{i, counts}, counter::obj{i, counts}); + ~EraseOnDestruct() { + (void)m_map; + m_map->erase(counter::obj{m_counter.get() + 1, m_counter.counts()}); } +}; + +} // namespace + +TEST_CASE("reentrant_destruct") { + auto counts = counter{}; + INFO(counts); - // add some elements auto map = map_t(); - for (size_t i = 0; i < 10; ++i) { - map.try_emplace(counter::obj{i, counts}, counter::obj{i, counts}); - } - map.replace(std::move(container)); + /* + This doesn't work, it is not something that can be supported with using std::vector. + I'll leave the code here so it's not lost though. - REQUIRE(map.size() == 100U); for (size_t i = 0; i < 100; ++i) { - REQUIRE(map.contains(counter::obj{i, counts})); + map.try_emplace(counter::obj{i, counts}, std::make_unique(map, i, counts)); } + map.erase(counter::obj{0, counts}); + */ }