Skip to content

Commit

Permalink
Fix noexcept specification
Browse files Browse the repository at this point in the history
  • Loading branch information
miscco committed Apr 23, 2021
1 parent d4c3384 commit 05252ff
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
35 changes: 22 additions & 13 deletions stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -3771,13 +3771,16 @@ namespace ranges {
}

_NODISCARD constexpr decltype(auto) operator*() const
noexcept(noexcept(_STD get<_Index>(*_Current))) /* strengthened */ {
if constexpr (is_reference_v<range_reference_t<_Base>>) {
return _STD get<_Index>(*_Current);
} else {
using _ElemTy = remove_cv_t<tuple_element_t<_Index, range_reference_t<_Base>>>;
return static_cast<_ElemTy>(_STD get<_Index>(*_Current));
}
noexcept(noexcept(_STD get<_Index>(*_Current))) /* strengthened */
requires is_reference_v<range_reference_t<_Base>> {
return _STD get<_Index>(*_Current);
}

_NODISCARD constexpr decltype(auto) operator*() const noexcept(
is_nothrow_move_constructible_v<remove_cv_t<tuple_element_t<_Index, range_reference_t<_Base>>>> //
&& noexcept(_STD get<_Index>(*_Current))) /* strengthened */ {
using _ElemTy = remove_cv_t<tuple_element_t<_Index, range_reference_t<_Base>>>;
return static_cast<_ElemTy>(_STD get<_Index>(*_Current));
}

constexpr _Iterator& operator++() noexcept(noexcept(++_Current)) /* strengthened */ {
Expand Down Expand Up @@ -3840,16 +3843,22 @@ namespace ranges {

_NODISCARD constexpr decltype(auto) operator[](const difference_type _Idx) const
noexcept(noexcept(_STD get<_Index>(*(_Current + _Idx)))) /* strengthened */
requires random_access_range<_Base>&& is_reference_v<range_reference_t<_Base>> {
#if _ITERATOR_DEBUG_LEVEL != 0
_Verify_offset(_Idx);
#endif // _ITERATOR_DEBUG_LEVEL != 0
return _STD get<_Index>(*(_Current + _Idx));
}

_NODISCARD constexpr decltype(auto) operator[](const difference_type _Idx) const noexcept(
is_nothrow_move_constructible_v<remove_cv_t<tuple_element_t<_Index, range_reference_t<_Base>>>> //
&& noexcept(_STD get<_Index>(*(_Current + _Idx)))) /* strengthened */
requires random_access_range<_Base> {
#if _ITERATOR_DEBUG_LEVEL != 0
_Verify_offset(_Idx);
#endif // _ITERATOR_DEBUG_LEVEL != 0
if constexpr (is_reference_v<range_reference_t<_Base>>) {
return _STD get<_Index>(*(_Current + _Idx));
} else {
using _ElemTy = remove_cv_t<tuple_element_t<_Index, range_reference_t<_Base>>>;
return static_cast<_ElemTy>(_STD get<_Index>(*(_Current + _Idx)));
}
using _ElemTy = remove_cv_t<tuple_element_t<_Index, range_reference_t<_Base>>>;
return static_cast<_ElemTy>(_STD get<_Index>(*(_Current + _Idx)));
}

_NODISCARD friend constexpr bool operator==(const _Iterator& _Left, const _Iterator& _Right) noexcept(
Expand Down
15 changes: 15 additions & 0 deletions tests/std/tests/P0896R4_views_drop/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,21 @@ int main() {
test_one(lst, only_four_ints);
}

// Validate a non-view borrowed range
{
constexpr span s{some_ints};
STATIC_ASSERT(test_one(s, expected_output));
test_one(s, expected_output);
}

{ // Validate a view borrowed range

constexpr auto v =
views::iota(0ull, ranges::size(some_ints)) | std::views::transform([](auto i) { return some_ints[i]; });
STATIC_ASSERT(test_one(v));
test_one(v);
}

// Validate an output range
STATIC_ASSERT((output_range_test(), true));
output_range_test();
Expand Down

0 comments on commit 05252ff

Please sign in to comment.