[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / libcxx / include / __iterator / incrementable_traits.h
blob604e9580ef7cadce15e3e990ef9cadf87dda46ac
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 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___ITERATOR_INCREMENTABLE_TRAITS_H
11 #define _LIBCPP___ITERATOR_INCREMENTABLE_TRAITS_H
13 #include <__concepts/arithmetic.h>
14 #include <__config>
15 #include <__type_traits/conditional.h>
16 #include <__type_traits/is_object.h>
17 #include <__type_traits/is_primary_template.h>
18 #include <__type_traits/make_signed.h>
19 #include <__type_traits/remove_cvref.h>
20 #include <__utility/declval.h>
21 #include <cstddef>
23 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24 # pragma GCC system_header
25 #endif
27 _LIBCPP_BEGIN_NAMESPACE_STD
29 #if _LIBCPP_STD_VER >= 20
31 // [incrementable.traits]
32 template<class> struct incrementable_traits {};
34 template<class _Tp>
35 requires is_object_v<_Tp>
36 struct incrementable_traits<_Tp*> {
37 using difference_type = ptrdiff_t;
40 template<class _Ip>
41 struct incrementable_traits<const _Ip> : incrementable_traits<_Ip> {};
43 template<class _Tp>
44 concept __has_member_difference_type = requires { typename _Tp::difference_type; };
46 template<__has_member_difference_type _Tp>
47 struct incrementable_traits<_Tp> {
48 using difference_type = typename _Tp::difference_type;
51 template<class _Tp>
52 concept __has_integral_minus =
53 requires(const _Tp& __x, const _Tp& __y) {
54 { __x - __y } -> integral;
57 template<__has_integral_minus _Tp>
58 requires (!__has_member_difference_type<_Tp>)
59 struct incrementable_traits<_Tp> {
60 using difference_type = make_signed_t<decltype(std::declval<_Tp>() - std::declval<_Tp>())>;
63 template <class>
64 struct iterator_traits;
66 // Let `RI` be `remove_cvref_t<I>`. The type `iter_difference_t<I>` denotes
67 // `incrementable_traits<RI>::difference_type` if `iterator_traits<RI>` names a specialization
68 // generated from the primary template, and `iterator_traits<RI>::difference_type` otherwise.
69 template <class _Ip>
70 using iter_difference_t = typename conditional_t<__is_primary_template<iterator_traits<remove_cvref_t<_Ip> > >::value,
71 incrementable_traits<remove_cvref_t<_Ip> >,
72 iterator_traits<remove_cvref_t<_Ip> > >::difference_type;
74 #endif // _LIBCPP_STD_VER >= 20
76 _LIBCPP_END_NAMESPACE_STD
78 #endif // _LIBCPP___ITERATOR_INCREMENTABLE_TRAITS_H