1 // -*- C++ -*- 2 //===----------------------------------------------------------------------===// 3 // 4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 // See https://llvm.org/LICENSE.txt for license information. 6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef _LIBCPP___ITERATOR_READABLE_TRAITS_H 11 #define _LIBCPP___ITERATOR_READABLE_TRAITS_H 12 13 #include <__config> 14 #include <__iterator/concepts.h> 15 16 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 17 #pragma GCC system_header 18 #endif 19 20 _LIBCPP_PUSH_MACROS 21 #include <__undef_macros> 22 23 _LIBCPP_BEGIN_NAMESPACE_STD 24 25 #if !defined(_LIBCPP_HAS_NO_RANGES) 26 27 // [readable.traits] 28 template<class> struct __cond_value_type {}; 29 30 template<class _Tp> 31 requires is_object_v<_Tp> 32 struct __cond_value_type<_Tp> { using value_type = remove_cv_t<_Tp>; }; 33 34 template<class _Tp> 35 concept __has_member_value_type = requires { typename _Tp::value_type; }; 36 37 template<class _Tp> 38 concept __has_member_element_type = requires { typename _Tp::element_type; }; 39 40 template<class> struct indirectly_readable_traits {}; 41 42 template<class _Ip> 43 requires is_array_v<_Ip> 44 struct indirectly_readable_traits<_Ip> { 45 using value_type = remove_cv_t<remove_extent_t<_Ip>>; 46 }; 47 48 template<class _Ip> 49 struct indirectly_readable_traits<const _Ip> : indirectly_readable_traits<_Ip> {}; 50 51 template<class _Tp> 52 struct indirectly_readable_traits<_Tp*> : __cond_value_type<_Tp> {}; 53 54 template<__has_member_value_type _Tp> 55 struct indirectly_readable_traits<_Tp> 56 : __cond_value_type<typename _Tp::value_type> {}; 57 58 template<__has_member_element_type _Tp> 59 struct indirectly_readable_traits<_Tp> 60 : __cond_value_type<typename _Tp::element_type> {}; 61 62 // Pre-emptively applies LWG3541 63 template<__has_member_value_type _Tp> 64 requires __has_member_element_type<_Tp> 65 struct indirectly_readable_traits<_Tp> {}; 66 template<__has_member_value_type _Tp> 67 requires __has_member_element_type<_Tp> && 68 same_as<remove_cv_t<typename _Tp::element_type>, 69 remove_cv_t<typename _Tp::value_type>> 70 struct indirectly_readable_traits<_Tp> 71 : __cond_value_type<typename _Tp::value_type> {}; 72 73 template <class> 74 struct iterator_traits; 75 76 // Let `RI` be `remove_cvref_t<I>`. The type `iter_value_t<I>` denotes 77 // `indirectly_readable_traits<RI>::value_type` if `iterator_traits<RI>` names a specialization 78 // generated from the primary template, and `iterator_traits<RI>::value_type` otherwise. 79 template <class _Ip> 80 using iter_value_t = typename conditional_t<__is_primary_template<iterator_traits<remove_cvref_t<_Ip> > >::value, 81 indirectly_readable_traits<remove_cvref_t<_Ip> >, 82 iterator_traits<remove_cvref_t<_Ip> > >::value_type; 83 84 #endif // !defined(_LIBCPP_HAS_NO_RANGES) 85 86 _LIBCPP_END_NAMESPACE_STD 87 88 _LIBCPP_POP_MACROS 89 90 #endif // _LIBCPP___ITERATOR_READABLE_TRAITS_H 91