Skip to content

Commit

Permalink
[libc++][NFC] Update precondition comments when testing subspan asser…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
ldionne committed Apr 11, 2023
1 parent 3acf9b9 commit 2e9058c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@

// <span>
//
// template<size_t Offset, size_t Count = dynamic_extent>
// constexpr span<element_type, see-below> subspan() const;
//
// Requires: Offset <= size() && (Count == dynamic_extent || Count <= size() - Offset)
//
// constexpr span<element_type, dynamic_extent> subspan(
// size_type offset, size_type count = dynamic_extent) const;
//
// Requires: (0 <= Offset && Offset <= size())
// && (Count == dynamic_extent || Count >= 0 && Offset + Count <= size())
// Requires: offset <= size() && (count == dynamic_extent || count <= size() - offset)

// Make sure that creating a sub-span with an incorrect number of elements triggers an assertion.

Expand Down Expand Up @@ -44,13 +48,13 @@ int main(int, char**) {
std::array<int, 3> array{0, 1, 2};
std::span<int, 3> const s(array.data(), array.size());
TEST_LIBCPP_ASSERT_FAILURE(s.subspan(4), "span<T, N>::subspan(offset, count): offset out of range");
// s.subspan<4>() caught at compile-time (tested elsewhere)
// s.subspan<4>() caught at compile-time (tested in libcxx/test/std/containers/views/views.span/span.sub/subspan.verify.cpp)

TEST_LIBCPP_ASSERT_FAILURE(s.subspan(0, 4), "span<T, N>::subspan(offset, count): count out of range");
// s.subspan<0, 4>() caught at compile-time (tested elsewhere)
// s.subspan<0, 4>() caught at compile-time (tested in libcxx/test/std/containers/views/views.span/span.sub/subspan.verify.cpp)

TEST_LIBCPP_ASSERT_FAILURE(s.subspan(1, 3), "span<T, N>::subspan(offset, count): offset + count out of range");
// s.subspan<1, 3>() caught at compile-time (tested elsewhere)
// s.subspan<1, 3>() caught at compile-time (tested in libcxx/test/std/containers/views/views.span/span.sub/subspan.verify.cpp)
}

return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// <span>

// template<size_t Offset, size_t Count = dynamic_extent>
// constexpr span<element_type, see below> subspan() const;
// constexpr span<element_type, see-below> subspan() const;
//
// Mandates: Offset <= Extent && (Count == dynamic_extent || Count <= Extent - Offset) is true.

Expand Down

0 comments on commit 2e9058c

Please sign in to comment.