Path: blob/main/contrib/llvm-project/libcxx/include/__iterator/incrementable_traits.h
35233 views
// -*- C++ -*-1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//89#ifndef _LIBCPP___ITERATOR_INCREMENTABLE_TRAITS_H10#define _LIBCPP___ITERATOR_INCREMENTABLE_TRAITS_H1112#include <__concepts/arithmetic.h>13#include <__config>14#include <__type_traits/conditional.h>15#include <__type_traits/is_object.h>16#include <__type_traits/is_primary_template.h>17#include <__type_traits/make_signed.h>18#include <__type_traits/remove_cvref.h>19#include <__utility/declval.h>20#include <cstddef>2122#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)23# pragma GCC system_header24#endif2526_LIBCPP_BEGIN_NAMESPACE_STD2728#if _LIBCPP_STD_VER >= 202930// [incrementable.traits]31template <class>32struct incrementable_traits {};3334template <class _Tp>35requires is_object_v<_Tp>36struct incrementable_traits<_Tp*> {37using difference_type = ptrdiff_t;38};3940template <class _Ip>41struct incrementable_traits<const _Ip> : incrementable_traits<_Ip> {};4243template <class _Tp>44concept __has_member_difference_type = requires { typename _Tp::difference_type; };4546template <__has_member_difference_type _Tp>47struct incrementable_traits<_Tp> {48using difference_type = typename _Tp::difference_type;49};5051template <class _Tp>52concept __has_integral_minus = requires(const _Tp& __x, const _Tp& __y) {53{ __x - __y } -> integral;54};5556template <__has_integral_minus _Tp>57requires(!__has_member_difference_type<_Tp>)58struct incrementable_traits<_Tp> {59using difference_type = make_signed_t<decltype(std::declval<_Tp>() - std::declval<_Tp>())>;60};6162template <class>63struct iterator_traits;6465// Let `RI` be `remove_cvref_t<I>`. The type `iter_difference_t<I>` denotes66// `incrementable_traits<RI>::difference_type` if `iterator_traits<RI>` names a specialization67// generated from the primary template, and `iterator_traits<RI>::difference_type` otherwise.68template <class _Ip>69using iter_difference_t =70typename conditional_t<__is_primary_template<iterator_traits<remove_cvref_t<_Ip> > >::value,71incrementable_traits<remove_cvref_t<_Ip> >,72iterator_traits<remove_cvref_t<_Ip> > >::difference_type;7374#endif // _LIBCPP_STD_VER >= 207576_LIBCPP_END_NAMESPACE_STD7778#endif // _LIBCPP___ITERATOR_INCREMENTABLE_TRAITS_H798081