Skip to content

Commit

Permalink
adl_begin, adl_end now takes auto &, and [[nodiscard]] index_valid
Browse files Browse the repository at this point in the history
More consistent with std::ranges::begin
  • Loading branch information
OleErikPeistorpet committed Jun 4, 2024
1 parent 0bd4b90 commit fe6b6ec
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions util.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ using oel::ssize;
}


/** @brief Check if index is valid (within bounds for operator[])
*
//! Returns true if index is within bounds (for operator[])
/**
* Requires that `r.size()` or `end(r) - begin(r)` is valid. */
template< typename Integral, typename SizedRangeLike >
constexpr bool index_valid(SizedRangeLike & r, Integral index)
[[nodiscard]] constexpr bool index_valid(SizedRangeLike & r, Integral index)
{
static_assert( sizeof(Integral) >= sizeof _detail::Size(r) or std::is_unsigned_v<Integral>,
"Mismatched index type, please use a wider integer (or unsigned)" );
Expand Down Expand Up @@ -104,10 +104,10 @@ inline constexpr for_overwrite_t for_overwrite; //!< An instance of for_overwrit

//! Same as `begin(range)` with a previous `using std::begin;`. For use in classes with a member named begin
inline constexpr auto adl_begin =
[](auto && range) -> decltype(begin(range)) { return begin(range); };
[](auto & range) -> decltype(begin(range)) { return begin(range); };
//! Same as `end(range)` with a previous `using std::end;`. For use in classes with a member named end
inline constexpr auto adl_end =
[](auto && range) -> decltype(end(range)) { return end(range); };
[](auto & range) -> decltype(end(range)) { return end(range); };



Expand Down

0 comments on commit fe6b6ec

Please sign in to comment.