Skip to content

Commit

Permalink
static_assert in _detail::Size
Browse files Browse the repository at this point in the history
  • Loading branch information
OleErikPeistorpet committed Jun 5, 2024
1 parent a2c6059 commit 51d88b2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion auxi/range_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ namespace _detail
>
constexpr auto Size(Range && r, None...)
-> decltype(end(r) - begin(r))
{ return end(r) - begin(r); }
{ return end(r) - begin(r);
static_assert(std::is_copy_constructible_v< iterator_t<Range> > or !std::is_lvalue_reference_v<Range>);
}
}

} // oel
Expand Down
5 changes: 3 additions & 2 deletions util.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ inline constexpr auto as_unsigned =
* Ill-formed if `r.size()` is ill-formed and `begin(r)` cannot be subtracted from `end(r)` (SFINAE-friendly) */
template< typename SizedRangeLike >
constexpr auto ssize(SizedRangeLike && r)
-> std::common_type_t< ptrdiff_t, decltype(as_signed( _detail::Size(r) )) >
-> std::common_type_t<ptrdiff_t, decltype( as_signed(_detail::Size(r)) )>
{
return std::common_type_t< ptrdiff_t, decltype(as_signed( _detail::Size(r) )) >(_detail::Size(r));
return std::common_type_t<ptrdiff_t, decltype( as_signed(_detail::Size(r)) )>
(_detail::Size( static_cast<SizedRangeLike &&>(r) ));
}

namespace view
Expand Down

0 comments on commit 51d88b2

Please sign in to comment.