mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 00:37:35 +00:00
AK: Add nodiscard
attribute to Find functions
This commit is contained in:
parent
ef4b98be52
commit
c860d8f5be
1 changed files with 3 additions and 3 deletions
|
@ -13,7 +13,7 @@
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
template<typename TEndIterator, IteratorPairWith<TEndIterator> TIterator, typename TUnaryPredicate>
|
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) {
|
for (; first != last; ++first) {
|
||||||
if (pred(*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>
|
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); });
|
return find_if(first, last, [&](auto const& v) { return Traits<T>::equals(value, v); });
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename TEndIterator, IteratorPairWith<TEndIterator> TIterator, typename T>
|
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();
|
return find_if(first, last, [&](auto const& v) { return Traits<T>::equals(value, v); }).index();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue