Skip to content

Commit

Permalink
Implement LWG-4096 views::iota(views::iota(0)) should be rejected (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
frederick-vs-ja authored Jul 5, 2024
1 parent 4bffb54 commit 679783a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -1044,10 +1044,10 @@ namespace ranges {
struct _Iota_fn {
template <class _Ty>
_NODISCARD _STATIC_CALL_OPERATOR constexpr auto operator()(_Ty&& _Val) _CONST_CALL_OPERATOR
noexcept(noexcept(iota_view(static_cast<_Ty&&>(_Val))))
requires requires { iota_view(static_cast<_Ty&&>(_Val)); }
noexcept(noexcept(iota_view<decay_t<_Ty>>(static_cast<_Ty&&>(_Val))))
requires requires { iota_view<decay_t<_Ty>>(static_cast<_Ty&&>(_Val)); }
{
return iota_view(static_cast<_Ty&&>(_Val));
return iota_view<decay_t<_Ty>>(static_cast<_Ty&&>(_Val));
}

template <class _Ty1, class _Ty2>
Expand Down
15 changes: 15 additions & 0 deletions tests/std/tests/P0896R4_views_iota/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ static_assert(ranges::_Advanceable<long long>);
template <class W, class B>
concept CanViewIota = requires(W w, B b) { views::iota(w, b); };

template <class W>
concept CanUnaryViewsIota = requires(W&& w) { views::iota(forward<W>(w)); };

template <class R>
concept CanSize = requires(R& r) { ranges::size(r); };

Expand Down Expand Up @@ -333,6 +336,18 @@ constexpr bool test_gh_3025() {
return true;
}

// LWG-4096 "views::iota(views::iota(0)) should be rejected"
static_assert(CanUnaryViewsIota<int>);
static_assert(CanUnaryViewsIota<const char*>);
static_assert(CanUnaryViewsIota<ranges::iterator_t<ranges::iota_view<long long>>>);
static_assert(!CanUnaryViewsIota<ranges::iota_view<int>>);
static_assert(!CanUnaryViewsIota<ranges::iota_view<const char*>>);
static_assert(!CanUnaryViewsIota<ranges::iota_view<ranges::iterator_t<ranges::iota_view<long long>>>>);
static_assert(!CanUnaryViewsIota<ranges::iota_view<int, int>>);
static_assert(!CanUnaryViewsIota<ranges::iota_view<const char*, const char*>>);
static_assert(!CanUnaryViewsIota<ranges::iota_view<ranges::iterator_t<ranges::iota_view<long long>>,
ranges::iterator_t<ranges::iota_view<long long>>>>);

int main() {
// Validate standard signed integer types
static_assert((test_integral<signed char>(), true));
Expand Down

0 comments on commit 679783a

Please sign in to comment.