77 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef _LIBCPP___ITERATOR_PRODUCT_ITERATOR_H10#define _LIBCPP___ITERATOR_PRODUCT_ITERATOR_H11 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 iterator15// is a proxy over two separate underlying iterators. The concept of product iterators16// allows algorithms to operate over these underlying iterators separately, opening the17// 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::__size21// 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_header39#endif40 41_LIBCPP_BEGIN_NAMESPACE_STD42 43template <class _Iterator>44struct __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 57template <class _Tp, size_t = 0>58struct __is_product_iterator : false_type {};59 60template <class _Tp>61struct __is_product_iterator<_Tp, sizeof(__product_iterator_traits<_Tp>) * 0> : true_type {};62 63template <class _Tp, size_t _Size, class = void>64struct __is_product_iterator_of_size : false_type {};65 66template <class _Tp, size_t _Size>67struct __is_product_iterator_of_size<_Tp, _Size, __enable_if_t<__product_iterator_traits<_Tp>::__size == _Size> >68 : true_type {};69 70template <class _Iterator, size_t _Nth>71using __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_STD75 76#endif // _LIBCPP___ITERATOR_PRODUCT_ITERATOR_H77