From 507430f9374b3f8f5f8968cda0c07f7d8962cfc3 Mon Sep 17 00:00:00 2001 From: Maxime Arthaud Date: Wed, 4 Sep 2024 03:40:16 -0700 Subject: [PATCH] Fix for boost 1.86.0 flat_map::extract_sequence Summary: Boost 1.86.0 has a bug with flat_map::extract_sequence. Let's use a workaround for now. See https://github.com/boostorg/container/issues/288 for upstream report. Reviewed By: arnaudvenet Differential Revision: D62103078 fbshipit-source-id: c54777faff875635ed025b16e78a99aaf555453f --- include/sparta/FlatMap.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/sparta/FlatMap.h b/include/sparta/FlatMap.h index af64712..bd3ebce 100644 --- a/include/sparta/FlatMap.h +++ b/include/sparta/FlatMap.h @@ -280,6 +280,18 @@ class FlatMap final break; } default: { +#if (BOOST_VERSION / 100) >= 1086 + // TODO(T200541423): Boost 1.86.0 has a bug with `extract_sequence()` and + // `adopt_sequence`. Let's disable the optimization for now. See + // https://github.com/boostorg/container/issues/288 + for (auto it = m_map.begin(); it != m_map.end();) { + if (!predicate(it->first, it->second)) { + it = m_map.erase(it); + } else { + ++it; + } + } +#else // Use boost `flat_map` API to get the underlying container and // apply a remove_if + erase. This allows to perform a filter in O(n). auto container = m_map.extract_sequence(); @@ -293,6 +305,7 @@ class FlatMap final container.end()); m_map.adopt_sequence(boost::container::ordered_unique_range, std::move(container)); +#endif break; } }