Skip to content

Commit

Permalink
ldionne's recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
strega-nil committed Jul 18, 2024
1 parent 89c15f3 commit d186443
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 22 deletions.
2 changes: 1 addition & 1 deletion libcxx/docs/ReleaseNotes/19.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------------------------
Expand Down
8 changes: 4 additions & 4 deletions libcxx/include/__algorithm/ranges_find_last.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
namespace ranges {

template <class _Iter, class _Sent, class _Pred, class _Proj>
_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);
Expand Down Expand Up @@ -78,7 +78,7 @@ struct __fn {
struct __op {
const _Type& __value;
template <class _Elem>
constexpr decltype(auto) operator()(_Elem&& __elem) const {
_LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator()(_Elem&& __elem) const {
return std::forward<_Elem>(__elem) == __value;
}
};
Expand All @@ -105,7 +105,7 @@ struct __fn {
struct __op {
_Pred& __pred;
template <class _Elem>
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));
}
};
Expand Down Expand Up @@ -135,7 +135,7 @@ struct __fn {
struct __op {
_Pred& __pred;
template <class _Elem>
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));
}
};
Expand Down
5 changes: 5 additions & 0 deletions libcxx/include/algorithm
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,24 @@ namespace ranges {
template<forward_iterator I, sentinel_for<I> S, class T, class Proj = identity>
requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
constexpr subrange<I> find_last(I first, S last, const T& value, Proj proj = {}); // since C++23
template<forward_range R, class T, class Proj = identity>
requires
indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
constexpr borrowed_subrange_t<R> find_last(R&& r, const T& value, Proj proj = {}); // since C++23
template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
indirect_unary_predicate<projected<I, Proj>> Pred>
constexpr subrange<I> find_last_if(I first, S last, Pred pred, Proj proj = {}); // since C++23
template<forward_range R, class Proj = identity,
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
constexpr borrowed_subrange_t<R> find_last_if(R&& r, Pred pred, Proj proj = {}); // since C++23
template<forward_iterator I, sentinel_for<I> S, class Proj = identity,
indirect_unary_predicate<projected<I, Proj>> Pred>
constexpr subrange<I> find_last_if_not(I first, S last, Pred pred, Proj proj = {}); // since C++23
template<forward_range R, class Proj = identity,
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
constexpr borrowed_subrange_t<R> find_last_if_not(R&& r, Pred pred, Proj proj = {}); // since C++23
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <algorithm>
#include <array>
#include <cassert>
#include <deque>
#include <ranges>
#include <vector>

Expand Down Expand Up @@ -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<char, wchar_t, int, long, TriviallyComparable<char>, TriviallyComparable<wchar_t>>{},
types::for_each(types::type_list<char, int, TriviallyComparable<char>>{},
[]<class T> {
types::for_each(types::forward_iterator_list<T*>{}, []<class Iter> {
test_iterators<Iter>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,7 @@ struct NonConstComparable {
};

template <class T>
struct add_const_to_ptr;
template <class T>
struct add_const_to_ptr<T*> {
using type = const T*;
};
template <class T>
using add_const_to_ptr_t = add_const_to_ptr<T>::type;
using add_const_to_ptr_t = std::add_pointer_t<std::add_const_t<std::remove_pointer_t<T>>>;

constexpr bool test() {
test_iterator_classes<std::type_identity_t, std::type_identity_t>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,7 @@ struct NonConstComparable {
};

template <class T>
struct add_const_to_ptr;
template <class T>
struct add_const_to_ptr<T*> {
using type = const T*;
};
template <class T>
using add_const_to_ptr_t = add_const_to_ptr<T>::type;
using add_const_to_ptr_t = std::add_pointer_t<std::add_const_t<std::remove_pointer_t<T>>>;

constexpr bool test() {
test_iterator_classes<std::type_identity_t, std::type_identity_t>();
Expand Down

0 comments on commit d186443

Please sign in to comment.