[libcxx-commits] [libcxx] [libc++] [test] Improve test coverage for containers' scary.pass.cpp (PR #131550)

via libcxx-commits libcxx-commits at lists.llvm.org
Sun Mar 30 21:26:34 PDT 2025


================
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <flat_map>
+
+// class flat_map
+// class flat_multimap
+
+// Extension: SCARY/N2913 iterator compatibility between flat_map and flat_multimap
+
+#include <flat_map>
+
+#include "test_macros.h"
+
+void test() {
+  typedef std::flat_map<int, int> M1;
+  typedef std::flat_multimap<int, int> M2;
+
+  ASSERT_SAME_TYPE(M1::iterator, M2::iterator);
+  ASSERT_SAME_TYPE(M1::const_iterator, M2::const_iterator);
----------------
halbi2 wrote:

> > The proposal is to make `std::flat_set::iterator` the same as `std::flat_multiset::iterator`.
> 
> It didn't. When the paper was written even `boost::flat_set` didn't exist, so it couldn't know `flat_set` at all.

I mean this PR. libc++ does not currently make `std::set<T>::iterator` synonymous of `std::vector<T>::iterator` but it does make it synonymous of `std::multiset<T>::iterator`.

I see why one may want `std::flat_set<T, Less>::iterator` different from `std::flat_set<T, Greater>::iterator`: they are sorted differently, and maybe this is usable somehow. I have not seen why `std::flat_set<T, Less>::iterator` should ever be different from `std::flat_multiset<T, Less>::iterator`, because their sole difference is whether the elements are unique.

But let it pass.

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


More information about the libcxx-commits mailing list