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

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Mar 25 14:29:56 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);
----------------
ldionne wrote:

http://wg21.link/N2911 was never standardized as a requirement AFAICT, so this is all kind of to the implementer's preference.

Our reasoning for using non-SCARY iterators in `flat_foo` were discussed in the review for `flat_set` here amongst other things: https://github.com/llvm/llvm-project/pull/125241#discussion_r1937783913. TLDR is that:
- it prevents users from mixing `std::vector::iterator` with `std::flat_set::iterator` which is almost certainly a unintended mistake
- it allows encoding the property that the range is sorted in the iterator type, which we might be able to use for some optimizations

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


More information about the libcxx-commits mailing list