[libcxx-commits] [libcxx] [libc++] Introduce `__product_iterator_traits` and optimise `flat_map::insert` (PR #139454)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri May 16 10:46:29 PDT 2025


================
@@ -0,0 +1,69 @@
+//===----------------------------------------------------------------------===//
+//
+// 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___PRODUCT_ITERATOR_H
+#define _LIBCPP___PRODUCT_ITERATOR_H
+
+// Product iterators are iterators that contain two or more underlying iterators.
+//
+// For example, std::flat_map stores its data into two separate containers, and its iterator
+// is a proxy over two separate underlying iterators. The concept of product iterators
+// allows algorithms to operate over these underlying iterators separately, opening the
+// door to various optimizations.
+//
+// If __product_iterator_traits can be instantiated, the following functions and associated types must be provided:
+// - static constexpr size_t Traits::__size
+//   The number of underlying iterators inside the product iterator.
+//
+// - template <size_t _N>
----------------
ldionne wrote:

As discussed just now, would it be useful to have a function like `__make_product_iterator(It1, It2, It3, ... ItN)`? I can imagine this being useful in algorithms that may want to perform operations on a single iterator in the product, but which need to still return a product iterator as a result. This is similar to what we do with segmented iterators and also wrapped iterators.

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


More information about the libcxx-commits mailing list