Skip to content

Commit

Permalink
ranges_extras.h: findIndex()
Browse files Browse the repository at this point in the history
Upstreaming of a piece from Quaternion.
  • Loading branch information
KitsuneRal committed Nov 29, 2024
1 parent fb51cc1 commit fe3fcc8
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Quotient/ranges_extras.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,16 @@ inline constexpr auto findIndirect(RangeT&& range, const ValT& value, ProjT proj
return findIndirect(std::ranges::begin(range), std::ranges::end(range), value, std::move(proj));
}

//! \brief An indexOf() alternative for any range
//!
//! Unlike QList::indexOf(), returns `range.size()` if \p value is not found
template <typename RangeT, typename ValT, typename ProjT = std::identity>
requires std::indirectly_comparable<std::ranges::iterator_t<RangeT>, const ValT*,
std::ranges::equal_to, ProjT>
inline auto findIndex(const RangeT& range, const ValT& value, ProjT proj = {})
{
using namespace std::ranges;
return distance(begin(range), find(range, value, std::move(proj)));
}

}

0 comments on commit fe3fcc8

Please sign in to comment.