[libcxx-commits] [libcxx] [libc++] constexpr flat_map (PR #137453)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri May 30 10:32:37 PDT 2025


================
@@ -67,23 +67,57 @@ void test() {
   M m;
   m.insert(cpp17_input_iterator<P*>(ar1), cpp17_input_iterator<P*>(ar1 + sizeof(ar1) / sizeof(ar1[0])));
   assert(m.size() == 3);
-  M expected{{1, 1}, {2, 1}, {3, 1}};
-  assert(m == expected);
+
+  assert(std::ranges::equal(m.keys(), KeyContainer{1, 2, 3}));
+  check_possible_values(
+      m.values(),
+      std::vector<std::vector<double>>{
+          {1, 1.5, 2},
+          {1, 1.5, 2},
+          {1, 1.5, 2},
+      });
+
+  auto m_copy = m;
 
   m.insert(cpp17_input_iterator<P*>(ar2), cpp17_input_iterator<P*>(ar2 + sizeof(ar2) / sizeof(ar2[0])));
   assert(m.size() == 5);
-  M expected2{{0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}};
-  assert(m == expected2);
+
----------------
ldionne wrote:

I think I would find this easier to understand if you instead did:

```
auto m2 = m;
m2.insert(...);

check_possible_values(
      m2.values(),
      std::vector<std::vector<double>>{
          {1, 1.5, 2},
          {m[1]},
          {m[2]},
          {m[3]},
          {1, 1.5, 2},
      });
```

This isolates test cases a bit more. WDYT?

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


More information about the libcxx-commits mailing list