[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


================
@@ -468,6 +473,18 @@ inline constexpr auto zip = __zip::__fn{};
 } // namespace views
 } // namespace ranges
 
+template <class _Iter>
+  requires _Iter::__is_zip_view_iterator::value
+struct __product_iterator_traits<_Iter> {
+  static constexpr size_t __size = tuple_size<decltype(std::declval<_Iter>().__current_)>::value;
+
+  template <size_t _Nth>
+    requires(_Nth < __size)
+  _LIBCPP_HIDE_FROM_ABI static constexpr auto __get_iterator_element(_Iter __it) {
+    return std::get<_Nth>(__it.__current_);
+  }
----------------
ldionne wrote:

Do you intend to be making copies here? You're making a copy of the `zip_view::iterator` as an argument to the function, and you're making a copy of the sub-iterator in the return value.

This should get a test case.

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


More information about the libcxx-commits mailing list