Skip to content

Commit

Permalink
Proper version of iterator_traits for pointers when concepts are not …
Browse files Browse the repository at this point in the history
…present.
  • Loading branch information
andrey-khropov committed Dec 25, 2023
1 parent 3ab1627 commit 524bc85
Showing 1 changed file with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,11 @@ struct _LIBCPP_TEMPLATE_VIS iterator_traits
};
#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)

template<class _Tp>

#if !defined(_LIBCPP_HAS_NO_CONCEPTS)

template<class _Tp>
requires is_object_v<_Tp>
#endif
struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*>
{
typedef ptrdiff_t difference_type;
Expand All @@ -417,6 +418,30 @@ struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*>
#endif
};

#else // !defined(_LIBCPP_HAS_NO_CONCEPTS)

template <class _Tp, bool is_pointer_to_object>
struct _LIBCPP_TEMPLATE_VIS __iterator_traits_pointer
{
typedef ptrdiff_t difference_type;
typedef typename remove_cv<_Tp>::type value_type;
typedef _Tp* pointer;
typedef _Tp& reference;
typedef random_access_iterator_tag iterator_category;
#if _LIBCPP_STD_VER > 17
typedef contiguous_iterator_tag iterator_concept;
#endif
};

template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS __iterator_traits_pointer<_Tp, false> {};

template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*> : public __iterator_traits_pointer<_Tp, is_object_v<_Tp>> {};

#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)


template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
struct __has_iterator_category_convertible_to
: is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>
Expand Down

0 comments on commit 524bc85

Please sign in to comment.