diff --git a/libcxx/include/__algorithm/equal.h b/libcxx/include/__algorithm/equal.h --- a/libcxx/include/__algorithm/equal.h +++ b/libcxx/include/__algorithm/equal.h @@ -33,8 +33,8 @@ template _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) { - typedef typename iterator_traits<_InputIterator1>::value_type __v1; - typedef typename iterator_traits<_InputIterator2>::value_type __v2; + typedef typename iterator_traits<_InputIterator1>::reference __v1; + typedef typename iterator_traits<_InputIterator2>::reference __v2; return _VSTD::equal(__first1, __last1, __first2, __equal_to<__v1, __v2>()); } @@ -72,8 +72,8 @@ template _LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) { - typedef typename iterator_traits<_InputIterator1>::value_type __v1; - typedef typename iterator_traits<_InputIterator2>::value_type __v2; + typedef typename iterator_traits<_InputIterator1>::reference __v1; + typedef typename iterator_traits<_InputIterator2>::reference __v2; return _VSTD::__equal(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>(), typename iterator_traits<_InputIterator1>::iterator_category(), typename iterator_traits<_InputIterator2>::iterator_category()); diff --git a/libcxx/test/libcxx/algorithms/equal.pass.cpp b/libcxx/test/libcxx/algorithms/equal.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/algorithms/equal.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11 + +// + +// check that std::equal can accept iterators with cv-qualified types. + +#include + +template +void f() { + int a[3]{1, 2, 3}; + T1* x = a; + T2* y = a; + (void)std::equal(x, x + 3, y, y + 3); + (void)std::equal(y, y + 3, x, x + 3); + (void)std::equal(x, x + 3, y); + (void)std::equal(y, y + 3, x); +} + +int main(int, char**) { + f(); + f(); + f(); + f(); + f(); + f(); + f(); + return 0; +}