Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:32

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP___CXX03___ITERATOR_INCREMENTABLE_TRAITS_H
0011 #define _LIBCPP___CXX03___ITERATOR_INCREMENTABLE_TRAITS_H
0012 
0013 #include <__cxx03/__concepts/arithmetic.h>
0014 #include <__cxx03/__config>
0015 #include <__cxx03/__type_traits/conditional.h>
0016 #include <__cxx03/__type_traits/is_object.h>
0017 #include <__cxx03/__type_traits/is_primary_template.h>
0018 #include <__cxx03/__type_traits/make_signed.h>
0019 #include <__cxx03/__type_traits/remove_cvref.h>
0020 #include <__cxx03/__utility/declval.h>
0021 #include <__cxx03/cstddef>
0022 
0023 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0024 #  pragma GCC system_header
0025 #endif
0026 
0027 _LIBCPP_BEGIN_NAMESPACE_STD
0028 
0029 #if _LIBCPP_STD_VER >= 20
0030 
0031 // [incrementable.traits]
0032 template <class>
0033 struct incrementable_traits {};
0034 
0035 template <class _Tp>
0036   requires is_object_v<_Tp>
0037 struct incrementable_traits<_Tp*> {
0038   using difference_type = ptrdiff_t;
0039 };
0040 
0041 template <class _Ip>
0042 struct incrementable_traits<const _Ip> : incrementable_traits<_Ip> {};
0043 
0044 template <class _Tp>
0045 concept __has_member_difference_type = requires { typename _Tp::difference_type; };
0046 
0047 template <__has_member_difference_type _Tp>
0048 struct incrementable_traits<_Tp> {
0049   using difference_type = typename _Tp::difference_type;
0050 };
0051 
0052 template <class _Tp>
0053 concept __has_integral_minus = requires(const _Tp& __x, const _Tp& __y) {
0054   { __x - __y } -> integral;
0055 };
0056 
0057 template <__has_integral_minus _Tp>
0058   requires(!__has_member_difference_type<_Tp>)
0059 struct incrementable_traits<_Tp> {
0060   using difference_type = make_signed_t<decltype(std::declval<_Tp>() - std::declval<_Tp>())>;
0061 };
0062 
0063 template <class>
0064 struct iterator_traits;
0065 
0066 // Let `RI` be `remove_cvref_t<I>`. The type `iter_difference_t<I>` denotes
0067 // `incrementable_traits<RI>::difference_type` if `iterator_traits<RI>` names a specialization
0068 // generated from the primary template, and `iterator_traits<RI>::difference_type` otherwise.
0069 template <class _Ip>
0070 using iter_difference_t =
0071     typename conditional_t<__is_primary_template<iterator_traits<remove_cvref_t<_Ip> > >::value,
0072                            incrementable_traits<remove_cvref_t<_Ip> >,
0073                            iterator_traits<remove_cvref_t<_Ip> > >::difference_type;
0074 
0075 #endif // _LIBCPP_STD_VER >= 20
0076 
0077 _LIBCPP_END_NAMESPACE_STD
0078 
0079 #endif // _LIBCPP___CXX03___ITERATOR_INCREMENTABLE_TRAITS_H