diff --git a/Quotient/ranges_extras.h b/Quotient/ranges_extras.h index 9555409ba..20a68c947 100644 --- a/Quotient/ranges_extras.h +++ b/Quotient/ranges_extras.h @@ -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 + requires std::indirectly_comparable, 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))); +} + }