[libcxx-commits] [libcxx] [libc++] Move out `flat_map::iterator` (for reusing it in flat_multimap) (PR #117445)

via libcxx-commits libcxx-commits at lists.llvm.org
Sun Dec 8 05:29:14 PST 2024


================
@@ -0,0 +1,171 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___FLAT_MAP_KEY_VALUE_ITERATOR_H
+#define _LIBCPP___FLAT_MAP_KEY_VALUE_ITERATOR_H
+
+#include <__compare/three_way_comparable.h>
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__iterator/iterator_traits.h>
+#include <__memory/addressof.h>
+#include <__ranges/access.h>
+#include <__type_traits/conditional.h>
+#include <__type_traits/maybe_const.h>
+#include <__utility/move.h>
+#include <__utility/pair.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Owner, class _KeyContainer, class _MappedContainer, bool _Const>
----------------
huixie90 wrote:

@ldionne  We could be a little bit SCARY where we don' allow the mix of `flat_map` and `flat_multimap`. But we can allow `flat_map<int, int, std::less<int>>::iterator` with `flat_map<int, int, std::greater<int>>::iterator` . That is what we did for `map`
https://godbolt.org/z/57zTGoGd3

to achieve this, we could do something like

```
template <class _Tag, 
                  class _KeyContainer, 
                  class _MappedContainer,
                  class _Reference,
                  class _ConstReference,
                  class _ValueType,
                  class _DifferenceType,
                  bool _Const>
struct __key_value_iterator
``` 

where `_Tag` can be `__flat_map_tag` or `__flat_multimap_tag`

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


More information about the libcxx-commits mailing list