diff --git a/libcxx/docs/ReleaseNotes/19.rst b/libcxx/docs/ReleaseNotes/19.rst index 03a021023aa5e5..f19ba150933758 100644 --- a/libcxx/docs/ReleaseNotes/19.rst +++ b/libcxx/docs/ReleaseNotes/19.rst @@ -55,7 +55,7 @@ Implemented Papers - P2231R1 - Missing ``constexpr`` in ``std::optional`` and ``std::variant`` - P0019R8 - ``std::atomic_ref`` - P2389R2 - Alias template ``dims`` for the ``extents`` of ``mdspan`` -- P1223R5 - ``find_last`` +- P1223R5 - ``ranges::find_last()``, ``ranges::find_last_if()``, and ``ranges::find_last_if_not()`` Improvements and New Features ----------------------------- diff --git a/libcxx/include/__algorithm/ranges_find_last.h b/libcxx/include/__algorithm/ranges_find_last.h index e6ca74349081b6..95f7e77b8ccbea 100644 --- a/libcxx/include/__algorithm/ranges_find_last.h +++ b/libcxx/include/__algorithm/ranges_find_last.h @@ -37,7 +37,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { template -_LIBCPP_HIDE_FROM_ABI constexpr static subrange<_Iter> +_LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter> __find_last_impl(_Iter __first, _Sent __last, _Pred __pred, _Proj& __proj) { if (__first == __last) { return subrange<_Iter>(__first, __first); @@ -78,7 +78,7 @@ struct __fn { struct __op { const _Type& __value; template - constexpr decltype(auto) operator()(_Elem&& __elem) const { + _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator()(_Elem&& __elem) const { return std::forward<_Elem>(__elem) == __value; } }; @@ -105,7 +105,7 @@ struct __fn { struct __op { _Pred& __pred; template - constexpr decltype(auto) operator()(_Elem&& __elem) const { + _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator()(_Elem&& __elem) const { return std::invoke(__pred, std::forward<_Elem>(__elem)); } }; @@ -135,7 +135,7 @@ struct __fn { struct __op { _Pred& __pred; template - constexpr decltype(auto) operator()(_Elem&& __elem) const { + _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator()(_Elem&& __elem) const { return !std::invoke(__pred, std::forward<_Elem>(__elem)); } }; diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm index e7f7ee00591b20..698e6f5cb7ad1f 100644 --- a/libcxx/include/algorithm +++ b/libcxx/include/algorithm @@ -105,19 +105,24 @@ namespace ranges { template S, class T, class Proj = identity> requires indirect_binary_predicate, const T*> constexpr subrange find_last(I first, S last, const T& value, Proj proj = {}); // since C++23 + template requires indirect_binary_predicate, Proj>, const T*> constexpr borrowed_subrange_t find_last(R&& r, const T& value, Proj proj = {}); // since C++23 + template S, class Proj = identity, indirect_unary_predicate> Pred> constexpr subrange find_last_if(I first, S last, Pred pred, Proj proj = {}); // since C++23 + template, Proj>> Pred> constexpr borrowed_subrange_t find_last_if(R&& r, Pred pred, Proj proj = {}); // since C++23 + template S, class Proj = identity, indirect_unary_predicate> Pred> constexpr subrange find_last_if_not(I first, S last, Pred pred, Proj proj = {}); // since C++23 + template, Proj>> Pred> constexpr borrowed_subrange_t find_last_if_not(R&& r, Pred pred, Proj proj = {}); // since C++23 diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last.pass.cpp index 499528fab2cbcb..bc7b99de82d52f 100644 --- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last.pass.cpp +++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last.pass.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include @@ -154,12 +153,12 @@ class TriviallyComparable { ElementT el_; public: - TEST_CONSTEXPR TriviallyComparable(ElementT el) : el_(el) {} + constexpr TriviallyComparable(ElementT el) : el_(el) {} bool operator==(const TriviallyComparable&) const = default; }; constexpr bool test() { - types::for_each(types::type_list, TriviallyComparable>{}, + types::for_each(types::type_list>{}, [] { types::for_each(types::forward_iterator_list{}, [] { test_iterators(); diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if.pass.cpp index 0ce3cae693038b..a15f81bd4e481a 100644 --- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if.pass.cpp +++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if.pass.cpp @@ -184,13 +184,7 @@ struct NonConstComparable { }; template -struct add_const_to_ptr; -template -struct add_const_to_ptr { - using type = const T*; -}; -template -using add_const_to_ptr_t = add_const_to_ptr::type; +using add_const_to_ptr_t = std::add_pointer_t>>; constexpr bool test() { test_iterator_classes(); diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if_not.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if_not.pass.cpp index 87538a5acd4125..bb0e411acf0fa2 100644 --- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if_not.pass.cpp +++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if_not.pass.cpp @@ -184,13 +184,7 @@ struct NonConstComparable { }; template -struct add_const_to_ptr; -template -struct add_const_to_ptr { - using type = const T*; -}; -template -using add_const_to_ptr_t = add_const_to_ptr::type; +using add_const_to_ptr_t = std::add_pointer_t>>; constexpr bool test() { test_iterator_classes();