2021-04-19 14:44:42 -07:00
|
|
|
// -*- C++ -*-
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP___ITERATOR_ITERATOR_TRAITS_H
|
|
|
|
#define _LIBCPP___ITERATOR_ITERATOR_TRAITS_H
|
|
|
|
|
2022-11-02 20:27:42 +01:00
|
|
|
#include <__concepts/arithmetic.h>
|
|
|
|
#include <__concepts/constructible.h>
|
|
|
|
#include <__concepts/convertible_to.h>
|
|
|
|
#include <__concepts/copyable.h>
|
|
|
|
#include <__concepts/equality_comparable.h>
|
|
|
|
#include <__concepts/same_as.h>
|
|
|
|
#include <__concepts/totally_ordered.h>
|
2021-04-19 14:44:42 -07:00
|
|
|
#include <__config>
|
2024-10-31 02:20:10 +01:00
|
|
|
#include <__cstddef/ptrdiff_t.h>
|
2022-08-13 23:10:31 +02:00
|
|
|
#include <__fwd/pair.h>
|
2021-04-19 14:44:42 -07:00
|
|
|
#include <__iterator/incrementable_traits.h>
|
|
|
|
#include <__iterator/readable_traits.h>
|
2022-12-21 00:07:17 +01:00
|
|
|
#include <__type_traits/common_reference.h>
|
|
|
|
#include <__type_traits/conditional.h>
|
2025-03-26 08:55:47 +01:00
|
|
|
#include <__type_traits/detected_or.h>
|
2022-12-21 00:07:17 +01:00
|
|
|
#include <__type_traits/disjunction.h>
|
2024-09-05 08:28:33 -04:00
|
|
|
#include <__type_traits/enable_if.h>
|
|
|
|
#include <__type_traits/integral_constant.h>
|
2022-12-21 00:07:17 +01:00
|
|
|
#include <__type_traits/is_convertible.h>
|
|
|
|
#include <__type_traits/is_object.h>
|
|
|
|
#include <__type_traits/is_primary_template.h>
|
|
|
|
#include <__type_traits/is_reference.h>
|
2025-03-29 05:07:31 -04:00
|
|
|
#include <__type_traits/is_referenceable.h>
|
2022-12-21 00:07:17 +01:00
|
|
|
#include <__type_traits/is_valid_expansion.h>
|
2025-03-26 08:55:47 +01:00
|
|
|
#include <__type_traits/nat.h>
|
2022-12-21 00:07:17 +01:00
|
|
|
#include <__type_traits/remove_const.h>
|
|
|
|
#include <__type_traits/remove_cv.h>
|
|
|
|
#include <__type_traits/remove_cvref.h>
|
|
|
|
#include <__type_traits/void_t.h>
|
|
|
|
#include <__utility/declval.h>
|
2021-04-19 14:44:42 -07:00
|
|
|
|
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2022-02-01 20:16:40 -05:00
|
|
|
# pragma GCC system_header
|
2021-04-19 14:44:42 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
|
2023-02-14 00:56:09 +01:00
|
|
|
#if _LIBCPP_STD_VER >= 20
|
2021-04-19 14:44:42 -07:00
|
|
|
|
2021-04-22 11:05:30 -04:00
|
|
|
template <class _Tp>
|
|
|
|
concept __dereferenceable = requires(_Tp& __t) {
|
2025-03-29 05:07:31 -04:00
|
|
|
{ *__t } -> __referenceable; // not required to be equality-preserving
|
2021-04-22 11:05:30 -04:00
|
|
|
};
|
|
|
|
|
2021-04-19 14:44:42 -07:00
|
|
|
// [iterator.traits]
|
|
|
|
template <__dereferenceable _Tp>
|
[libc++][NFC] Qualify declval
While it's not necessary to qualify calls to `declval` it makes error messages very crypric if the declaration isn't reachable anymore
For example:
```
/home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__chrono/duration.h:53:66: error: no type named 'type' in 'std::common_type<long, long>'
typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
/home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__type_traits/common_type.h:107:14: note: in instantiation of template class 'std::common_type<std::chrono::duration<long, std::ratio<3600, 1>>, std::chrono::duration<long, std::ratio<3600, 1>>>' requested here
: public common_type<_Tp, _Tp> {};
^
/home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__chrono/duration.h:279:58: note: in instantiation of template class 'std::common_type<std::chrono::duration<long, std::ratio<3600, 1>>>' requested here
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator+() const {return typename common_type<duration>::type(*this);}
^
/home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__chrono/duration.h:308:54: note: in instantiation of template class 'std::chrono::duration<long, std::ratio<3600, 1>>' requested here
typedef duration< int, ratio_multiply<ratio<24>, hours::period>> days;
^
/home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__chrono/duration.h:280:81: error: no type named 'type' in 'std::common_type<std::chrono::duration<long, std::ratio<3600, 1>>>'
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator-() const {return typename common_type<duration>::type(-__rep_);}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
/home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__chrono/duration.h:308:54: note: in instantiation of template class 'std::chrono::duration<long, std::ratio<3600, 1>>' requested here
typedef duration< int, ratio_multiply<ratio<24>, hours::period>> days;
^
/home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__chrono/duration.h:53:66: error: no type named 'type' in 'std::common_type<int, int>'
typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
/home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__type_traits/common_type.h:107:14: note: in instantiation of template class 'std::common_type<std::chrono::duration<int, std::ratio<86400, 1>>, std::chrono::duration<int, std::ratio<86400, 1>>>' requested here
: public common_type<_Tp, _Tp> {};
^
/home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__chrono/duration.h:279:58: note: in instantiation of template class 'std::common_type<std::chrono::duration<int, std::ratio<86400, 1>>>' requested here
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator+() const {return typename common_type<duration>::type(*this);}
^
/home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__chrono/duration.h:309:55: note: in instantiation of template class 'std::chrono::duration<int, std::ratio<86400, 1>>' requested here
typedef duration< int, ratio_multiply<ratio<7>, days::period>> weeks;
^
19 similar errors omitted
```
changes with qualification added to:
```
While building module 'std' imported from /home/nikolask/llvm-projects/libcxx/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp:13:
In file included from <module-includes>:17:
In file included from /home/nikolask/llvm-projects/libcxx/build/include/c++/v1/math.h:309:
In file included from /home/nikolask/llvm-projects/libcxx/build/include/c++/v1/limits:107:
In file included from /home/nikolask/llvm-projects/libcxx/build/include/c++/v1/type_traits:432:
In file included from /home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__type_traits/common_reference.h:13:
/home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__type_traits/common_type.h:28:43: error: declaration of 'declval' must be imported from module 'std.utility.__utility.declval' before it is required
using __cond_type = decltype(false ? std::declval<_Tp>() : std::declval<_Up>());
^
/home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__utility/declval.h:30:34: note: declaration here is not visible
decltype(std::__declval<_Tp>(0)) declval() _NOEXCEPT;
^
/home/nikolask/llvm-projects/libcxx/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp:13:10: fatal error: could not build module 'std'
#include <functional>
~~~~~~~~^
2 errors generated.
```
Reviewed By: ldionne, Mordante, #libc
Spies: libcxx-commits
Differential Revision: https://reviews.llvm.org/D130854
2022-07-31 21:54:25 +02:00
|
|
|
using iter_reference_t = decltype(*std::declval<_Tp&>());
|
2021-04-22 11:05:30 -04:00
|
|
|
|
2023-02-14 00:56:09 +01:00
|
|
|
#endif // _LIBCPP_STD_VER >= 20
|
2021-04-19 14:44:42 -07:00
|
|
|
|
|
|
|
template <class _Iter>
|
2025-04-09 23:47:57 +02:00
|
|
|
struct iterator_traits;
|
2021-04-19 14:44:42 -07:00
|
|
|
|
2025-04-09 23:47:57 +02:00
|
|
|
struct input_iterator_tag {};
|
|
|
|
struct output_iterator_tag {};
|
|
|
|
struct forward_iterator_tag : public input_iterator_tag {};
|
|
|
|
struct bidirectional_iterator_tag : public forward_iterator_tag {};
|
|
|
|
struct random_access_iterator_tag : public bidirectional_iterator_tag {};
|
2023-02-14 00:56:09 +01:00
|
|
|
#if _LIBCPP_STD_VER >= 20
|
2025-04-09 23:47:57 +02:00
|
|
|
struct contiguous_iterator_tag : public random_access_iterator_tag {};
|
2021-04-19 14:44:42 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
template <class _Iter>
|
|
|
|
struct __iter_traits_cache {
|
2025-03-23 21:01:25 +01:00
|
|
|
using type _LIBCPP_NODEBUG =
|
|
|
|
_If<__is_primary_template<iterator_traits<_Iter> >::value, _Iter, iterator_traits<_Iter> >;
|
2021-04-19 14:44:42 -07:00
|
|
|
};
|
|
|
|
template <class _Iter>
|
2025-01-08 17:12:59 +01:00
|
|
|
using _ITER_TRAITS _LIBCPP_NODEBUG = typename __iter_traits_cache<_Iter>::type;
|
2021-04-19 14:44:42 -07:00
|
|
|
|
|
|
|
struct __iter_concept_concept_test {
|
|
|
|
template <class _Iter>
|
2025-01-08 17:12:59 +01:00
|
|
|
using _Apply _LIBCPP_NODEBUG = typename _ITER_TRAITS<_Iter>::iterator_concept;
|
2021-04-19 14:44:42 -07:00
|
|
|
};
|
|
|
|
struct __iter_concept_category_test {
|
|
|
|
template <class _Iter>
|
2025-01-08 17:12:59 +01:00
|
|
|
using _Apply _LIBCPP_NODEBUG = typename _ITER_TRAITS<_Iter>::iterator_category;
|
2021-04-19 14:44:42 -07:00
|
|
|
};
|
|
|
|
struct __iter_concept_random_fallback {
|
|
|
|
template <class _Iter>
|
2025-01-08 17:12:59 +01:00
|
|
|
using _Apply _LIBCPP_NODEBUG =
|
|
|
|
__enable_if_t<__is_primary_template<iterator_traits<_Iter> >::value, random_access_iterator_tag>;
|
2021-04-19 14:44:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Iter, class _Tester>
|
|
|
|
struct __test_iter_concept : _IsValidExpansion<_Tester::template _Apply, _Iter>, _Tester {};
|
|
|
|
|
|
|
|
template <class _Iter>
|
|
|
|
struct __iter_concept_cache {
|
2025-03-23 21:01:25 +01:00
|
|
|
using type _LIBCPP_NODEBUG =
|
|
|
|
_Or<__test_iter_concept<_Iter, __iter_concept_concept_test>,
|
|
|
|
__test_iter_concept<_Iter, __iter_concept_category_test>,
|
|
|
|
__test_iter_concept<_Iter, __iter_concept_random_fallback> >;
|
2021-04-19 14:44:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Iter>
|
2025-01-08 17:12:59 +01:00
|
|
|
using _ITER_CONCEPT _LIBCPP_NODEBUG = typename __iter_concept_cache<_Iter>::type::template _Apply<_Iter>;
|
2021-04-19 14:44:42 -07:00
|
|
|
|
|
|
|
template <class _Tp>
|
|
|
|
struct __has_iterator_typedefs {
|
|
|
|
private:
|
2022-06-10 12:42:46 +02:00
|
|
|
template <class _Up>
|
|
|
|
static false_type __test(...);
|
2022-10-01 15:42:00 +02:00
|
|
|
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);
|
2023-12-18 14:01:33 -05:00
|
|
|
|
2021-04-19 14:44:42 -07:00
|
|
|
public:
|
2023-12-31 14:59:46 +01:00
|
|
|
static const bool value = decltype(__test<_Tp>(nullptr, nullptr, nullptr, nullptr, nullptr))::value;
|
2021-04-19 14:44:42 -07:00
|
|
|
};
|
|
|
|
|
2023-02-14 00:56:09 +01:00
|
|
|
#if _LIBCPP_STD_VER >= 20
|
2021-04-19 14:44:42 -07:00
|
|
|
|
2022-03-17 19:57:39 -07:00
|
|
|
// The `cpp17-*-iterator` exposition-only concepts have very similar names to the `Cpp17*Iterator` named requirements
|
|
|
|
// from `[iterator.cpp17]`. To avoid confusion between the two, the exposition-only concepts have been banished to
|
|
|
|
// a "detail" namespace indicating they have a niche use-case.
|
2021-04-19 14:44:42 -07:00
|
|
|
namespace __iterator_traits_detail {
|
|
|
|
template <class _Ip>
|
|
|
|
concept __cpp17_iterator = requires(_Ip __i) {
|
2025-03-29 05:07:31 -04:00
|
|
|
{ *__i } -> __referenceable;
|
2021-04-19 14:44:42 -07:00
|
|
|
{ ++__i } -> same_as<_Ip&>;
|
2025-03-29 05:07:31 -04:00
|
|
|
{ *__i++ } -> __referenceable;
|
2021-04-19 14:44:42 -07:00
|
|
|
} && copyable<_Ip>;
|
2023-12-18 14:01:33 -05:00
|
|
|
|
2021-04-19 14:44:42 -07:00
|
|
|
template <class _Ip>
|
|
|
|
concept __cpp17_input_iterator = __cpp17_iterator<_Ip> && equality_comparable<_Ip> && requires(_Ip __i) {
|
|
|
|
typename incrementable_traits<_Ip>::difference_type;
|
|
|
|
typename indirectly_readable_traits<_Ip>::value_type;
|
|
|
|
typename common_reference_t<iter_reference_t<_Ip>&&, typename indirectly_readable_traits<_Ip>::value_type&>;
|
|
|
|
typename common_reference_t<decltype(*__i++)&&, typename indirectly_readable_traits<_Ip>::value_type&>;
|
|
|
|
requires signed_integral<typename incrementable_traits<_Ip>::difference_type>;
|
|
|
|
};
|
2023-12-18 14:01:33 -05:00
|
|
|
|
2021-04-19 14:44:42 -07:00
|
|
|
template <class _Ip>
|
|
|
|
concept __cpp17_forward_iterator =
|
2023-01-21 13:38:43 +01:00
|
|
|
__cpp17_input_iterator<_Ip> && constructible_from<_Ip> && is_reference_v<iter_reference_t<_Ip>> &&
|
2021-04-19 14:44:42 -07:00
|
|
|
same_as<remove_cvref_t<iter_reference_t<_Ip>>, typename indirectly_readable_traits<_Ip>::value_type> &&
|
|
|
|
requires(_Ip __i) {
|
|
|
|
{ __i++ } -> convertible_to<_Ip const&>;
|
|
|
|
{ *__i++ } -> same_as<iter_reference_t<_Ip>>;
|
|
|
|
};
|
2023-12-18 14:01:33 -05:00
|
|
|
|
2021-04-19 14:44:42 -07:00
|
|
|
template <class _Ip>
|
|
|
|
concept __cpp17_bidirectional_iterator = __cpp17_forward_iterator<_Ip> && requires(_Ip __i) {
|
|
|
|
{ --__i } -> same_as<_Ip&>;
|
|
|
|
{ __i-- } -> convertible_to<_Ip const&>;
|
|
|
|
{ *__i-- } -> same_as<iter_reference_t<_Ip>>;
|
|
|
|
};
|
2023-12-18 14:01:33 -05:00
|
|
|
|
2021-04-19 14:44:42 -07:00
|
|
|
template <class _Ip>
|
|
|
|
concept __cpp17_random_access_iterator =
|
2021-06-07 13:48:45 -04:00
|
|
|
__cpp17_bidirectional_iterator<_Ip> && totally_ordered<_Ip> &&
|
2021-04-19 14:44:42 -07:00
|
|
|
requires(_Ip __i, typename incrementable_traits<_Ip>::difference_type __n) {
|
|
|
|
{ __i += __n } -> same_as<_Ip&>;
|
|
|
|
{ __i -= __n } -> same_as<_Ip&>;
|
|
|
|
{ __i + __n } -> same_as<_Ip>;
|
|
|
|
{ __n + __i } -> same_as<_Ip>;
|
|
|
|
{ __i - __n } -> same_as<_Ip>;
|
[libc++] Use -I instead of -isystem to include headers in the test suite
Using -isystem marks the headers as system headers, which means that we
don't actually get all the warnings that we'd normally get if we included
the headers as user headers.
The goal of the test suite is normally to mirror as closely as possible
how users would use the library. Technically, this change goes against
that philosophy, since users should be using `-isystem` (if they ever
need to specify the libc++ path explicitly, which should be a rare
occurence). However, I believe fishing out additional warnings from
the headers provides more value, hence this change. Ideally, we'd be
able to still use `-isystem`, but instruct Clang to still emit warnings
from the libc++ headers (e.g. we could tell Clang to emit warnings in
any file inside `<...>/usr/include/c++/v1`).
Reviewed By: #libc, ldionne, #libc_abi
Spies: Mordante, EricWF, mstorsjo, mgorny, aheejin, arichardson, philnik, jloser, libcxx-commits
Differential Revision: https://reviews.llvm.org/D118616
2022-03-03 12:10:30 +01:00
|
|
|
{ __i - __i } -> same_as<decltype(__n)>; // NOLINT(misc-redundant-expression) ; This is llvm.org/PR54114
|
2021-04-19 14:44:42 -07:00
|
|
|
{ __i[__n] } -> convertible_to<iter_reference_t<_Ip>>;
|
|
|
|
};
|
|
|
|
} // namespace __iterator_traits_detail
|
|
|
|
|
|
|
|
template <class _Ip>
|
|
|
|
concept __has_member_reference = requires { typename _Ip::reference; };
|
|
|
|
|
|
|
|
template <class _Ip>
|
|
|
|
concept __has_member_pointer = requires { typename _Ip::pointer; };
|
|
|
|
|
|
|
|
template <class _Ip>
|
|
|
|
concept __has_member_iterator_category = requires { typename _Ip::iterator_category; };
|
|
|
|
|
|
|
|
template <class _Ip>
|
|
|
|
concept __specifies_members = requires {
|
|
|
|
typename _Ip::value_type;
|
|
|
|
typename _Ip::difference_type;
|
|
|
|
requires __has_member_reference<_Ip>;
|
|
|
|
requires __has_member_iterator_category<_Ip>;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class>
|
|
|
|
struct __iterator_traits_member_pointer_or_void {
|
2025-03-23 21:01:25 +01:00
|
|
|
using type _LIBCPP_NODEBUG = void;
|
2021-04-19 14:44:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
template <__has_member_pointer _Tp>
|
|
|
|
struct __iterator_traits_member_pointer_or_void<_Tp> {
|
2025-03-23 21:01:25 +01:00
|
|
|
using type _LIBCPP_NODEBUG = typename _Tp::pointer;
|
2021-04-19 14:44:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Tp>
|
|
|
|
concept __cpp17_iterator_missing_members = !__specifies_members<_Tp> && __iterator_traits_detail::__cpp17_iterator<_Tp>;
|
|
|
|
|
|
|
|
template <class _Tp>
|
|
|
|
concept __cpp17_input_iterator_missing_members =
|
|
|
|
__cpp17_iterator_missing_members<_Tp> && __iterator_traits_detail::__cpp17_input_iterator<_Tp>;
|
|
|
|
|
|
|
|
// Otherwise, `pointer` names `void`.
|
|
|
|
template <class>
|
|
|
|
struct __iterator_traits_member_pointer_or_arrow_or_void {
|
2025-03-23 21:01:25 +01:00
|
|
|
using type _LIBCPP_NODEBUG = void;
|
2021-04-19 14:44:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// [iterator.traits]/3.2.1
|
|
|
|
// If the qualified-id `I::pointer` is valid and denotes a type, `pointer` names that type.
|
|
|
|
template <__has_member_pointer _Ip>
|
|
|
|
struct __iterator_traits_member_pointer_or_arrow_or_void<_Ip> {
|
2025-03-23 21:01:25 +01:00
|
|
|
using type _LIBCPP_NODEBUG = typename _Ip::pointer;
|
2021-04-19 14:44:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// Otherwise, if `decltype(declval<I&>().operator->())` is well-formed, then `pointer` names that
|
|
|
|
// type.
|
|
|
|
template <class _Ip>
|
2021-06-01 14:54:29 -07:00
|
|
|
requires requires(_Ip& __i) { __i.operator->(); } && (!__has_member_pointer<_Ip>)
|
2021-04-19 14:44:42 -07:00
|
|
|
struct __iterator_traits_member_pointer_or_arrow_or_void<_Ip> {
|
2025-03-23 21:01:25 +01:00
|
|
|
using type _LIBCPP_NODEBUG = decltype(std::declval<_Ip&>().operator->());
|
2021-04-19 14:44:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// Otherwise, `reference` names `iter-reference-t<I>`.
|
|
|
|
template <class _Ip>
|
|
|
|
struct __iterator_traits_member_reference {
|
2025-03-23 21:01:25 +01:00
|
|
|
using type _LIBCPP_NODEBUG = iter_reference_t<_Ip>;
|
2021-04-19 14:44:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// [iterator.traits]/3.2.2
|
|
|
|
// If the qualified-id `I::reference` is valid and denotes a type, `reference` names that type.
|
|
|
|
template <__has_member_reference _Ip>
|
|
|
|
struct __iterator_traits_member_reference<_Ip> {
|
2025-03-23 21:01:25 +01:00
|
|
|
using type _LIBCPP_NODEBUG = typename _Ip::reference;
|
2021-04-19 14:44:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// [iterator.traits]/3.2.3.4
|
|
|
|
// input_iterator_tag
|
|
|
|
template <class _Ip>
|
|
|
|
struct __deduce_iterator_category {
|
2025-03-23 21:01:25 +01:00
|
|
|
using type _LIBCPP_NODEBUG = input_iterator_tag;
|
2021-04-19 14:44:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// [iterator.traits]/3.2.3.1
|
|
|
|
// `random_access_iterator_tag` if `I` satisfies `cpp17-random-access-iterator`, or otherwise
|
|
|
|
template <__iterator_traits_detail::__cpp17_random_access_iterator _Ip>
|
|
|
|
struct __deduce_iterator_category<_Ip> {
|
2025-03-23 21:01:25 +01:00
|
|
|
using type _LIBCPP_NODEBUG = random_access_iterator_tag;
|
2021-04-19 14:44:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// [iterator.traits]/3.2.3.2
|
|
|
|
// `bidirectional_iterator_tag` if `I` satisfies `cpp17-bidirectional-iterator`, or otherwise
|
|
|
|
template <__iterator_traits_detail::__cpp17_bidirectional_iterator _Ip>
|
|
|
|
struct __deduce_iterator_category<_Ip> {
|
2025-03-23 21:01:25 +01:00
|
|
|
using type _LIBCPP_NODEBUG = bidirectional_iterator_tag;
|
2021-04-19 14:44:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// [iterator.traits]/3.2.3.3
|
|
|
|
// `forward_iterator_tag` if `I` satisfies `cpp17-forward-iterator`, or otherwise
|
|
|
|
template <__iterator_traits_detail::__cpp17_forward_iterator _Ip>
|
|
|
|
struct __deduce_iterator_category<_Ip> {
|
2025-03-23 21:01:25 +01:00
|
|
|
using type _LIBCPP_NODEBUG = forward_iterator_tag;
|
2021-04-19 14:44:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Ip>
|
|
|
|
struct __iterator_traits_iterator_category : __deduce_iterator_category<_Ip> {};
|
|
|
|
|
|
|
|
// [iterator.traits]/3.2.3
|
|
|
|
// If the qualified-id `I::iterator-category` is valid and denotes a type, `iterator-category` names
|
|
|
|
// that type.
|
|
|
|
template <__has_member_iterator_category _Ip>
|
|
|
|
struct __iterator_traits_iterator_category<_Ip> {
|
2025-03-23 21:01:25 +01:00
|
|
|
using type _LIBCPP_NODEBUG = typename _Ip::iterator_category;
|
2021-04-19 14:44:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// otherwise, it names void.
|
|
|
|
template <class>
|
|
|
|
struct __iterator_traits_difference_type {
|
2025-03-23 21:01:25 +01:00
|
|
|
using type _LIBCPP_NODEBUG = void;
|
2021-04-19 14:44:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// If the qualified-id `incrementable_traits<I>::difference_type` is valid and denotes a type, then
|
|
|
|
// `difference_type` names that type;
|
|
|
|
template <class _Ip>
|
|
|
|
requires requires { typename incrementable_traits<_Ip>::difference_type; }
|
|
|
|
struct __iterator_traits_difference_type<_Ip> {
|
2025-03-23 21:01:25 +01:00
|
|
|
using type _LIBCPP_NODEBUG = typename incrementable_traits<_Ip>::difference_type;
|
2021-04-19 14:44:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// [iterator.traits]/3.4
|
|
|
|
// Otherwise, `iterator_traits<I>` has no members by any of the above names.
|
|
|
|
template <class>
|
|
|
|
struct __iterator_traits {};
|
|
|
|
|
|
|
|
// [iterator.traits]/3.1
|
|
|
|
// If `I` has valid ([temp.deduct]) member types `difference-type`, `value-type`, `reference`, and
|
|
|
|
// `iterator-category`, then `iterator-traits<I>` has the following publicly accessible members:
|
|
|
|
template <__specifies_members _Ip>
|
|
|
|
struct __iterator_traits<_Ip> {
|
|
|
|
using iterator_category = typename _Ip::iterator_category;
|
|
|
|
using value_type = typename _Ip::value_type;
|
|
|
|
using difference_type = typename _Ip::difference_type;
|
|
|
|
using pointer = typename __iterator_traits_member_pointer_or_void<_Ip>::type;
|
|
|
|
using reference = typename _Ip::reference;
|
|
|
|
};
|
|
|
|
|
|
|
|
// [iterator.traits]/3.2
|
|
|
|
// Otherwise, if `I` satisfies the exposition-only concept `cpp17-input-iterator`,
|
|
|
|
// `iterator-traits<I>` has the following publicly accessible members:
|
|
|
|
template <__cpp17_input_iterator_missing_members _Ip>
|
|
|
|
struct __iterator_traits<_Ip> {
|
|
|
|
using iterator_category = typename __iterator_traits_iterator_category<_Ip>::type;
|
|
|
|
using value_type = typename indirectly_readable_traits<_Ip>::value_type;
|
|
|
|
using difference_type = typename incrementable_traits<_Ip>::difference_type;
|
|
|
|
using pointer = typename __iterator_traits_member_pointer_or_arrow_or_void<_Ip>::type;
|
|
|
|
using reference = typename __iterator_traits_member_reference<_Ip>::type;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Otherwise, if `I` satisfies the exposition-only concept `cpp17-iterator`, then
|
|
|
|
// `iterator_traits<I>` has the following publicly accessible members:
|
|
|
|
template <__cpp17_iterator_missing_members _Ip>
|
|
|
|
struct __iterator_traits<_Ip> {
|
|
|
|
using iterator_category = output_iterator_tag;
|
|
|
|
using value_type = void;
|
|
|
|
using difference_type = typename __iterator_traits_difference_type<_Ip>::type;
|
|
|
|
using pointer = void;
|
|
|
|
using reference = void;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Ip>
|
|
|
|
struct iterator_traits : __iterator_traits<_Ip> {
|
2025-01-08 17:12:59 +01:00
|
|
|
using __primary_template _LIBCPP_NODEBUG = iterator_traits;
|
2021-04-19 14:44:42 -07:00
|
|
|
};
|
|
|
|
|
2023-02-14 00:56:09 +01:00
|
|
|
#else // _LIBCPP_STD_VER >= 20
|
2021-04-19 14:44:42 -07:00
|
|
|
|
|
|
|
template <class _Iter, bool>
|
|
|
|
struct __iterator_traits {};
|
|
|
|
|
|
|
|
template <class _Iter, bool>
|
|
|
|
struct __iterator_traits_impl {};
|
|
|
|
|
|
|
|
template <class _Iter>
|
|
|
|
struct __iterator_traits_impl<_Iter, true> {
|
|
|
|
typedef typename _Iter::difference_type difference_type;
|
|
|
|
typedef typename _Iter::value_type value_type;
|
|
|
|
typedef typename _Iter::pointer pointer;
|
|
|
|
typedef typename _Iter::reference reference;
|
|
|
|
typedef typename _Iter::iterator_category iterator_category;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Iter>
|
|
|
|
struct __iterator_traits<_Iter, true>
|
|
|
|
: __iterator_traits_impl< _Iter,
|
|
|
|
is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
|
|
|
|
is_convertible<typename _Iter::iterator_category, output_iterator_tag>::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
|
|
|
|
// the client expects instead of failing at compile time.
|
|
|
|
|
|
|
|
template <class _Iter>
|
2025-04-09 23:47:57 +02:00
|
|
|
struct iterator_traits : __iterator_traits<_Iter, __has_iterator_typedefs<_Iter>::value> {
|
2025-01-08 17:12:59 +01:00
|
|
|
using __primary_template _LIBCPP_NODEBUG = iterator_traits;
|
2021-04-19 14:44:42 -07:00
|
|
|
};
|
2023-02-14 00:56:09 +01:00
|
|
|
#endif // _LIBCPP_STD_VER >= 20
|
2021-04-19 14:44:42 -07:00
|
|
|
|
|
|
|
template <class _Tp>
|
2023-02-14 00:56:09 +01:00
|
|
|
#if _LIBCPP_STD_VER >= 20
|
2021-04-19 14:44:42 -07:00
|
|
|
requires is_object_v<_Tp>
|
|
|
|
#endif
|
2025-04-09 23:47:57 +02:00
|
|
|
struct iterator_traits<_Tp*> {
|
2021-04-19 14:44:42 -07:00
|
|
|
typedef ptrdiff_t difference_type;
|
2022-09-06 00:33:34 +02:00
|
|
|
typedef __remove_cv_t<_Tp> value_type;
|
2021-04-19 14:44:42 -07:00
|
|
|
typedef _Tp* pointer;
|
|
|
|
typedef _Tp& reference;
|
|
|
|
typedef random_access_iterator_tag iterator_category;
|
2023-02-14 00:56:09 +01:00
|
|
|
#if _LIBCPP_STD_VER >= 20
|
2021-04-19 14:44:42 -07:00
|
|
|
typedef contiguous_iterator_tag iterator_concept;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2025-03-26 08:55:47 +01:00
|
|
|
template <class _Tp>
|
|
|
|
using __iterator_category _LIBCPP_NODEBUG = typename _Tp::iterator_category;
|
2021-04-19 14:44:42 -07:00
|
|
|
|
2025-03-26 08:55:47 +01:00
|
|
|
template <class _Tp>
|
|
|
|
using __iterator_concept _LIBCPP_NODEBUG = typename _Tp::iterator_concept;
|
2021-04-19 14:44:42 -07:00
|
|
|
|
2025-03-26 08:55:47 +01:00
|
|
|
template <class _Tp, class _Up>
|
|
|
|
using __has_iterator_category_convertible_to _LIBCPP_NODEBUG =
|
|
|
|
is_convertible<__detected_or_t<__nat, __iterator_category, iterator_traits<_Tp> >, _Up>;
|
2021-04-19 14:44:42 -07:00
|
|
|
|
|
|
|
template <class _Tp, class _Up>
|
2025-03-26 08:55:47 +01:00
|
|
|
using __has_iterator_concept_convertible_to _LIBCPP_NODEBUG =
|
|
|
|
is_convertible<__detected_or_t<__nat, __iterator_concept, _Tp>, _Up>;
|
2021-04-19 14:44:42 -07:00
|
|
|
|
|
|
|
template <class _Tp>
|
2025-01-08 17:12:59 +01:00
|
|
|
using __has_input_iterator_category _LIBCPP_NODEBUG = __has_iterator_category_convertible_to<_Tp, input_iterator_tag>;
|
2021-04-19 14:44:42 -07:00
|
|
|
|
|
|
|
template <class _Tp>
|
2025-01-08 17:12:59 +01:00
|
|
|
using __has_forward_iterator_category _LIBCPP_NODEBUG =
|
|
|
|
__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>;
|
2021-04-19 14:44:42 -07:00
|
|
|
|
|
|
|
template <class _Tp>
|
2025-01-08 17:12:59 +01:00
|
|
|
using __has_bidirectional_iterator_category _LIBCPP_NODEBUG =
|
|
|
|
__has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag>;
|
2021-04-19 14:44:42 -07:00
|
|
|
|
|
|
|
template <class _Tp>
|
2025-01-08 17:12:59 +01:00
|
|
|
using __has_random_access_iterator_category _LIBCPP_NODEBUG =
|
|
|
|
__has_iterator_category_convertible_to<_Tp, random_access_iterator_tag>;
|
2021-04-19 14:44:42 -07:00
|
|
|
|
2023-05-17 10:34:51 -07:00
|
|
|
// __libcpp_is_contiguous_iterator determines if an iterator is known by
|
2021-05-19 11:54:31 -04:00
|
|
|
// libc++ to be contiguous, either because it advertises itself as such
|
|
|
|
// (in C++20) or because it is a pointer type or a known trivial wrapper
|
|
|
|
// around a (possibly fancy) pointer type, such as __wrap_iter<T*>.
|
|
|
|
// Such iterators receive special "contiguous" optimizations in
|
|
|
|
// std::copy and std::sort.
|
2021-04-19 14:44:42 -07:00
|
|
|
//
|
2023-02-14 00:56:09 +01:00
|
|
|
#if _LIBCPP_STD_VER >= 20
|
2021-04-19 14:44:42 -07:00
|
|
|
template <class _Tp>
|
2023-05-17 10:34:51 -07:00
|
|
|
struct __libcpp_is_contiguous_iterator
|
2021-04-19 14:44:42 -07:00
|
|
|
: _Or< __has_iterator_category_convertible_to<_Tp, contiguous_iterator_tag>,
|
|
|
|
__has_iterator_concept_convertible_to<_Tp, contiguous_iterator_tag> > {};
|
|
|
|
#else
|
|
|
|
template <class _Tp>
|
2023-05-17 10:34:51 -07:00
|
|
|
struct __libcpp_is_contiguous_iterator : false_type {};
|
2021-04-19 14:44:42 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Any native pointer which is an iterator is also a contiguous iterator.
|
|
|
|
template <class _Up>
|
2023-05-17 10:34:51 -07:00
|
|
|
struct __libcpp_is_contiguous_iterator<_Up*> : true_type {};
|
2021-04-19 14:44:42 -07:00
|
|
|
|
2022-06-03 12:50:39 +02:00
|
|
|
template <class _Iter>
|
|
|
|
class __wrap_iter;
|
|
|
|
|
2021-04-19 14:44:42 -07:00
|
|
|
template <class _Tp>
|
2025-01-08 17:12:59 +01:00
|
|
|
using __has_exactly_input_iterator_category _LIBCPP_NODEBUG =
|
2023-05-17 10:34:51 -07:00
|
|
|
integral_constant<bool,
|
2021-04-19 14:44:42 -07:00
|
|
|
__has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value &&
|
2023-05-17 10:34:51 -07:00
|
|
|
!__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value>;
|
2021-04-19 14:44:42 -07:00
|
|
|
|
2022-07-04 22:45:49 +02:00
|
|
|
template <class _Tp>
|
2025-01-08 17:12:59 +01:00
|
|
|
using __has_exactly_forward_iterator_category _LIBCPP_NODEBUG =
|
2023-05-17 10:34:51 -07:00
|
|
|
integral_constant<bool,
|
2022-07-04 22:45:49 +02:00
|
|
|
__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value &&
|
2023-05-17 10:34:51 -07:00
|
|
|
!__has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag>::value>;
|
2022-07-04 22:45:49 +02:00
|
|
|
|
2022-07-13 18:07:26 +02:00
|
|
|
template <class _Tp>
|
2025-01-08 17:12:59 +01:00
|
|
|
using __has_exactly_bidirectional_iterator_category _LIBCPP_NODEBUG =
|
2023-05-17 10:34:51 -07:00
|
|
|
integral_constant<bool,
|
2022-07-13 18:07:26 +02:00
|
|
|
__has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag>::value &&
|
2023-05-17 10:34:51 -07:00
|
|
|
!__has_iterator_category_convertible_to<_Tp, random_access_iterator_tag>::value>;
|
2022-07-13 18:07:26 +02:00
|
|
|
|
2021-04-19 14:44:42 -07:00
|
|
|
template <class _InputIterator>
|
2025-01-08 17:12:59 +01:00
|
|
|
using __iter_value_type _LIBCPP_NODEBUG = typename iterator_traits<_InputIterator>::value_type;
|
2021-04-19 14:44:42 -07:00
|
|
|
|
|
|
|
template <class _InputIterator>
|
2025-01-08 17:12:59 +01:00
|
|
|
using __iter_key_type _LIBCPP_NODEBUG =
|
|
|
|
__remove_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>;
|
2021-04-19 14:44:42 -07:00
|
|
|
|
|
|
|
template <class _InputIterator>
|
2025-01-08 17:12:59 +01:00
|
|
|
using __iter_mapped_type _LIBCPP_NODEBUG = typename iterator_traits<_InputIterator>::value_type::second_type;
|
2021-04-19 14:44:42 -07:00
|
|
|
|
|
|
|
template <class _InputIterator>
|
2025-01-08 17:12:59 +01:00
|
|
|
using __iter_to_alloc_type _LIBCPP_NODEBUG =
|
2024-03-20 11:23:48 +01:00
|
|
|
pair<const typename iterator_traits<_InputIterator>::value_type::first_type,
|
|
|
|
typename iterator_traits<_InputIterator>::value_type::second_type>;
|
2021-04-19 14:44:42 -07:00
|
|
|
|
2022-07-24 15:28:15 +02:00
|
|
|
template <class _Iter>
|
2025-01-08 17:12:59 +01:00
|
|
|
using __iterator_category_type _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::iterator_category;
|
2022-07-24 15:28:15 +02:00
|
|
|
|
|
|
|
template <class _Iter>
|
2025-01-08 17:12:59 +01:00
|
|
|
using __iterator_pointer_type _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::pointer;
|
2022-07-24 15:28:15 +02:00
|
|
|
|
2022-08-04 10:54:13 -07:00
|
|
|
template <class _Iter>
|
2025-01-08 17:12:59 +01:00
|
|
|
using __iter_diff_t _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::difference_type;
|
2022-08-04 10:54:13 -07:00
|
|
|
|
2023-05-02 09:45:37 -07:00
|
|
|
template <class _Iter>
|
2025-01-08 17:12:59 +01:00
|
|
|
using __iter_reference _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::reference;
|
2023-05-02 09:45:37 -07:00
|
|
|
|
2023-06-26 14:07:50 -07:00
|
|
|
#if _LIBCPP_STD_VER >= 20
|
|
|
|
|
|
|
|
// [readable.traits]
|
|
|
|
|
|
|
|
// Let `RI` be `remove_cvref_t<I>`. The type `iter_value_t<I>` denotes
|
|
|
|
// `indirectly_readable_traits<RI>::value_type` if `iterator_traits<RI>` names a specialization
|
|
|
|
// generated from the primary template, and `iterator_traits<RI>::value_type` otherwise.
|
|
|
|
// This has to be in this file and not readable_traits.h to break the include cycle between the two.
|
|
|
|
template <class _Ip>
|
|
|
|
using iter_value_t =
|
|
|
|
typename conditional_t<__is_primary_template<iterator_traits<remove_cvref_t<_Ip> > >::value,
|
|
|
|
indirectly_readable_traits<remove_cvref_t<_Ip> >,
|
|
|
|
iterator_traits<remove_cvref_t<_Ip> > >::value_type;
|
|
|
|
|
|
|
|
#endif // _LIBCPP_STD_VER >= 20
|
|
|
|
|
2021-04-19 14:44:42 -07:00
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
|
|
|
#endif // _LIBCPP___ITERATOR_ITERATOR_TRAITS_H
|