1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef _LIBCPP___ITERATOR_PRODUCT_ITERATOR_H 10 #define _LIBCPP___ITERATOR_PRODUCT_ITERATOR_H 11 12 // Product iterators are iterators that contain two or more underlying iterators. 13 // 14 // For example, std::flat_map stores its data into two separate containers, and its iterator 15 // is a proxy over two separate underlying iterators. The concept of product iterators 16 // allows algorithms to operate over these underlying iterators separately, opening the 17 // door to various optimizations. 18 // 19 // If __product_iterator_traits can be instantiated, the following functions and associated types must be provided: 20 // - static constexpr size_t Traits::__size 21 // The number of underlying iterators inside the product iterator. 22 // 23 // - template <size_t _N> 24 // static decltype(auto) Traits::__get_iterator_element(It&& __it) 25 // Returns the _Nth iterator element of the given product iterator. 26 // 27 // - template <class... _Iters> 28 // static _Iterator __make_product_iterator(_Iters&&...); 29 // Creates a product iterator from the given underlying iterators. 30 31 #include <__config> 32 #include <__cstddef/size_t.h> 33 #include <__type_traits/enable_if.h> 34 #include <__type_traits/integral_constant.h> 35 #include <__utility/declval.h> 36 37 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 38 # pragma GCC system_header 39 #endif 40 41 _LIBCPP_BEGIN_NAMESPACE_STD 42 43 template <class _Iterator> 44 struct __product_iterator_traits; 45 /* exposition-only: 46 { 47 static constexpr size_t __size = ...; 48 49 template <size_t _N, class _Iter> 50 static decltype(auto) __get_iterator_element(_Iter&&); 51 52 template <class... _Iters> 53 static _Iterator __make_product_iterator(_Iters&&...); 54 }; 55 */ 56 57 template <class _Tp, size_t = 0> 58 struct __is_product_iterator : false_type {}; 59 60 template <class _Tp> 61 struct __is_product_iterator<_Tp, sizeof(__product_iterator_traits<_Tp>) * 0> : true_type {}; 62 63 template <class _Tp, size_t _Size, class = void> 64 struct __is_product_iterator_of_size : false_type {}; 65 66 template <class _Tp, size_t _Size> 67 struct __is_product_iterator_of_size<_Tp, _Size, __enable_if_t<__product_iterator_traits<_Tp>::__size == _Size> > 68 : true_type {}; 69 70 template <class _Iterator, size_t _Nth> 71 using __product_iterator_element_t _LIBCPP_NODEBUG = 72 decltype(__product_iterator_traits<_Iterator>::template __get_iterator_element<_Nth>(std::declval<_Iterator>())); 73 74 _LIBCPP_END_NAMESPACE_STD 75 76 #endif // _LIBCPP___ITERATOR_PRODUCT_ITERATOR_H 77