mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-08-16 17:00:35 +03:00
AK: Add nodiscard
attribute to Find functions
This commit is contained in:
parent
ef4b98be52
commit
c860d8f5be
Notes:
sideshowbarker
2024-07-17 09:45:12 +09:00
Author: https://github.com/ldm5180 Commit: https://github.com/SerenityOS/serenity/commit/c860d8f5be Pull-request: https://github.com/SerenityOS/serenity/pull/14395 Reviewed-by: https://github.com/linusg
@ -13,7 +13,7 @@
|
||||
namespace AK {
|
||||
|
||||
template<typename TEndIterator, IteratorPairWith<TEndIterator> TIterator, typename TUnaryPredicate>
|
||||
constexpr TIterator find_if(TIterator first, TEndIterator last, TUnaryPredicate&& pred)
|
||||
[[nodiscard]] constexpr TIterator find_if(TIterator first, TEndIterator last, TUnaryPredicate&& pred)
|
||||
{
|
||||
for (; first != last; ++first) {
|
||||
if (pred(*first)) {
|
||||
@ -24,13 +24,13 @@ constexpr TIterator find_if(TIterator first, TEndIterator last, TUnaryPredicate&
|
||||
}
|
||||
|
||||
template<typename TEndIterator, IteratorPairWith<TEndIterator> TIterator, typename T>
|
||||
constexpr TIterator find(TIterator first, TEndIterator last, T const& value)
|
||||
[[nodiscard]] constexpr TIterator find(TIterator first, TEndIterator last, T const& value)
|
||||
{
|
||||
return find_if(first, last, [&](auto const& v) { return Traits<T>::equals(value, v); });
|
||||
}
|
||||
|
||||
template<typename TEndIterator, IteratorPairWith<TEndIterator> TIterator, typename T>
|
||||
constexpr size_t find_index(TIterator first, TEndIterator last, T const& value) requires(requires(TIterator it) { it.index(); })
|
||||
[[nodiscard]] constexpr size_t find_index(TIterator first, TEndIterator last, T const& value) requires(requires(TIterator it) { it.index(); })
|
||||
{
|
||||
return find_if(first, last, [&](auto const& v) { return Traits<T>::equals(value, v); }).index();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user