[libcxx-commits] [PATCH] D130124: [libc++][ranges] fix `std::search_n` incorrect `static_assert`
Konstantin Varlamov via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jul 19 17:25:03 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9c0564a3a7df: [libc++][ranges] fix `std::search_n` incorrect `static_assert` (authored by huixie90, committed by var-const).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D130124/new/
https://reviews.llvm.org/D130124
Files:
libcxx/include/__algorithm/search_n.h
libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_n_pred.pass.cpp
Index: libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_n_pred.pass.cpp
===================================================================
--- libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_n_pred.pass.cpp
+++ libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search_n_pred.pass.cpp
@@ -158,12 +158,35 @@
count_equal::count = 0;
}
+class A {
+public:
+ A(int x, int y) : x_(x), y_(y) {}
+ int x() const { return x_; }
+ int y() const { return y_; }
+
+private:
+ int x_;
+ int y_;
+};
+
+struct Pred {
+ bool operator()(const A& l, int r) const { return l.x() == r; }
+};
+
int main(int, char**)
{
test<forward_iterator<const int*> >();
test<bidirectional_iterator<const int*> >();
test<random_access_iterator<const int*> >();
+ // test bug reported in https://reviews.llvm.org/D124079?#3661721
+ {
+ A a[] = {A(1, 2), A(2, 3), A(2, 4)};
+ int value = 2;
+ auto result = std::search_n(a, a + 3, 1, value, Pred());
+ assert(result == a + 1);
+ }
+
#if TEST_STD_VER > 17
static_assert(test_constexpr());
#endif
Index: libcxx/include/__algorithm/search_n.h
===================================================================
--- libcxx/include/__algorithm/search_n.h
+++ libcxx/include/__algorithm/search_n.h
@@ -163,7 +163,7 @@
_Size __count,
const _Tp& __value,
_BinaryPredicate __pred) {
- static_assert(__is_callable<_BinaryPredicate, decltype(*__first), decltype(*__last)>::value,
+ static_assert(__is_callable<_BinaryPredicate, decltype(*__first), const _Tp&>::value,
"BinaryPredicate has to be callable");
auto __proj = __identity();
return std::__search_n_impl(__first, __last, std::__convert_to_integral(__count), __value, __pred, __proj).first;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130124.445992.patch
Type: text/x-patch
Size: 1877 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220720/7091e453/attachment.bin>
More information about the libcxx-commits
mailing list