[libc++] Move __has_iterator_typedefs to the up-to-C++17 implementation of iterator_traits (#144265)

`__has_iterator_typedefs` is only used in the up-to-C++17 implementation
of `type_traits`. To make that clearer the struct is moved into that
code block.
This commit is contained in:
Nikolas Klauser
2025-06-18 15:55:06 +02:00
committed by GitHub
parent 1d6f1029f7
commit 9db7502d22

View File

@@ -71,23 +71,6 @@ struct random_access_iterator_tag : public bidirectional_iterator_tag {};
struct contiguous_iterator_tag : public random_access_iterator_tag {};
#endif
template <class _Tp>
struct __has_iterator_typedefs {
private:
template <class _Up>
static false_type __test(...);
template <class _Up>
static true_type
__test(__void_t<typename _Up::iterator_category>* = nullptr,
__void_t<typename _Up::difference_type>* = nullptr,
__void_t<typename _Up::value_type>* = nullptr,
__void_t<typename _Up::reference>* = nullptr,
__void_t<typename _Up::pointer>* = nullptr);
public:
static const bool value = decltype(__test<_Tp>(nullptr, nullptr, nullptr, nullptr, nullptr))::value;
};
#if _LIBCPP_STD_VER >= 20
// The `cpp17-*-iterator` exposition-only concepts have very similar names to the `Cpp17*Iterator` named requirements
@@ -322,6 +305,23 @@ struct __iterator_traits<_Iter, true>
is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value > {};
template <class _Tp>
struct __has_iterator_typedefs {
private:
template <class _Up>
static false_type __test(...);
template <class _Up>
static true_type
__test(__void_t<typename _Up::iterator_category>* = nullptr,
__void_t<typename _Up::difference_type>* = nullptr,
__void_t<typename _Up::value_type>* = nullptr,
__void_t<typename _Up::reference>* = nullptr,
__void_t<typename _Up::pointer>* = nullptr);
public:
static const bool value = decltype(__test<_Tp>(nullptr, nullptr, nullptr, nullptr, nullptr))::value;
};
// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
// exists. Else iterator_traits<Iterator> will be an empty class. This is a
// conforming extension which allows some programs to compile and behave as