[libcxx-commits] [libcxx] [libc++] implement std::flat_set (PR #125241)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Mar 21 12:21:57 PDT 2025


================
@@ -0,0 +1,103 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <flat_set>
+
+// iterator erase(const_iterator first, const_iterator last);
+
+#include <compare>
+#include <concepts>
+#include <deque>
+#include <flat_set>
+#include <functional>
+#include <utility>
+#include <vector>
+
+#include "MinSequenceContainer.h"
+#include "../helpers.h"
+#include "test_macros.h"
+#include "min_allocator.h"
+
+template <class KeyContainer>
+void test_one() {
+  using Key = typename KeyContainer::value_type;
+  using M   = std::flat_set<Key, std::less<Key>, KeyContainer>;
+  using I   = M::iterator;
+
+  int ar[] = {
+      1,
+      2,
+      3,
+      4,
+      5,
+      6,
+      7,
+      8,
+  };
+  M m(ar, ar + sizeof(ar) / sizeof(ar[0]));
+  assert(m.size() == 8);
+  std::same_as<I> decltype(auto) i1 = m.erase(m.cbegin(), m.cbegin());
+  assert(m.size() == 8);
+  assert(i1 == m.begin());
+  assert(*m.begin() == 1);
+  assert(*std::next(m.begin()) == 2);
----------------
ldionne wrote:

You could use this pattern here as well: `assert(m == make({1, 2, 3, 4, 5, 6, 7, 8}));`

https://github.com/llvm/llvm-project/pull/125241


More information about the libcxx-commits mailing list