mirror of
https://github.com/microsoft/GSL.git
synced 2025-03-12 22:28:06 -04:00
update span specialization of at, change some tests back to int i with narrowing for the comparisons.
This commit is contained in:
parent
3b9d15f49f
commit
a49ff1b8df
@ -806,7 +806,8 @@ template <class ElementType, std::size_t Extent>
|
||||
constexpr ElementType& at(span<ElementType, Extent> s, index i)
|
||||
{
|
||||
// No bounds checking here because it is done in span::operator[] called below
|
||||
return s[i];
|
||||
Ensures(i >= 0);
|
||||
return s[narrow_cast<std::size_t>(i)];
|
||||
}
|
||||
|
||||
// [span.obs] Free observer functions
|
||||
|
@ -153,24 +153,24 @@ TEST(span_test, from_pointer_length_constructor)
|
||||
int arr[4] = {1, 2, 3, 4};
|
||||
|
||||
{
|
||||
for (std::size_t i = 0; i < 4; ++i)
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
{
|
||||
span<int> s = {&arr[0], i};
|
||||
EXPECT_TRUE(s.size() == i);
|
||||
span<int> s = {&arr[0], narrow_cast<std::size_t>(i)};
|
||||
EXPECT_TRUE(s.size() == narrow_cast<std::size_t>(i));
|
||||
EXPECT_TRUE(s.data() == &arr[0]);
|
||||
EXPECT_TRUE(s.empty() == (i == 0));
|
||||
for (std::size_t j = 0; j < i; ++j)
|
||||
EXPECT_TRUE(arr[j] == s[j]);
|
||||
for (int j = 0; j < i; ++j)
|
||||
EXPECT_TRUE(arr[j] == s[narrow_cast<std::size_t>(j)]);
|
||||
}
|
||||
{
|
||||
span<int> s = {&arr[i], 4 - i};
|
||||
EXPECT_TRUE(s.size() == 4 - i);
|
||||
span<int> s = {&arr[i], 4 - narrow_cast<std::size_t>(i)};
|
||||
EXPECT_TRUE(s.size() == 4 - narrow_cast<std::size_t>(i));
|
||||
EXPECT_TRUE(s.data() == &arr[i]);
|
||||
EXPECT_TRUE(s.empty() == ((4 - i) == 0));
|
||||
|
||||
for (std::size_t j = 0; j < 4 - i; ++j)
|
||||
EXPECT_TRUE(arr[j + i] == s[j]);
|
||||
for (int j = 0; j < 4 - i; ++j)
|
||||
EXPECT_TRUE(arr[j + i] == s[narrow_cast<std::size_t>(j)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user