gsl::index ptrdiff_t -> size_t. remove span::at span::operator().

This commit is contained in:
Jordan Maples [MSFT]
2020-02-04 16:53:43 -08:00
parent 5a1e4f3953
commit d7e1611137
5 changed files with 39 additions and 111 deletions
+9 -17
View File
@@ -33,7 +33,7 @@ TEST(at_tests, static_array)
int a[4] = {1, 2, 3, 4};
const int(&c_a)[4] = a;
for (int i = 0; i < 4; ++i) {
for (std::size_t i = 0; i < 4; ++i) {
EXPECT_TRUE(&gsl::at(a, i) == &a[i]);
EXPECT_TRUE(&gsl::at(c_a, i) == &a[i]);
}
@@ -43,9 +43,7 @@ TEST(at_tests, static_array)
std::abort();
});
EXPECT_DEATH(gsl::at(a, -1), deathstring);
EXPECT_DEATH(gsl::at(a, 4), deathstring);
EXPECT_DEATH(gsl::at(c_a, -1), deathstring);
EXPECT_DEATH(gsl::at(c_a, 4), deathstring);
}
@@ -54,7 +52,7 @@ TEST(at_tests, std_array)
std::array<int, 4> a = {1, 2, 3, 4};
const std::array<int, 4>& c_a = a;
for (int i = 0; i < 4; ++i) {
for (std::size_t i = 0; i < 4; ++i) {
EXPECT_TRUE(&gsl::at(a, i) == &a[static_cast<std::size_t>(i)]);
EXPECT_TRUE(&gsl::at(c_a, i) == &a[static_cast<std::size_t>(i)]);
}
@@ -64,9 +62,7 @@ TEST(at_tests, std_array)
std::abort();
});
EXPECT_DEATH(gsl::at(a, -1), deathstring);
EXPECT_DEATH(gsl::at(a, 4), deathstring);
EXPECT_DEATH(gsl::at(c_a, -1), deathstring);
EXPECT_DEATH(gsl::at(c_a, 4), deathstring);
}
@@ -75,7 +71,7 @@ TEST(at_tests, std_vector)
std::vector<int> a = {1, 2, 3, 4};
const std::vector<int>& c_a = a;
for (int i = 0; i < 4; ++i) {
for (std::size_t i = 0; i < 4; ++i) {
EXPECT_TRUE(&gsl::at(a, i) == &a[static_cast<std::size_t>(i)]);
EXPECT_TRUE(&gsl::at(c_a, i) == &a[static_cast<std::size_t>(i)]);
}
@@ -85,9 +81,7 @@ TEST(at_tests, std_vector)
std::abort();
});
EXPECT_DEATH(gsl::at(a, -1), deathstring);
EXPECT_DEATH(gsl::at(a, 4), deathstring);
EXPECT_DEATH(gsl::at(c_a, -1), deathstring);
EXPECT_DEATH(gsl::at(c_a, 4), deathstring);
}
@@ -96,8 +90,8 @@ TEST(at_tests, InitializerList)
const std::initializer_list<int> a = {1, 2, 3, 4};
for (int i = 0; i < 4; ++i) {
EXPECT_TRUE(gsl::at(a, i) == i + 1);
EXPECT_TRUE(gsl::at({1, 2, 3, 4}, i) == i + 1);
EXPECT_TRUE(gsl::at(a, static_cast<std::size_t>(i)) == i + 1);
EXPECT_TRUE(gsl::at({1, 2, 3, 4}, static_cast<std::size_t>(i)) == i + 1);
}
std::set_terminate([] {
@@ -105,9 +99,7 @@ TEST(at_tests, InitializerList)
std::abort();
});
EXPECT_DEATH(gsl::at(a, -1), deathstring);
EXPECT_DEATH(gsl::at(a, 4), deathstring);
EXPECT_DEATH(gsl::at({1, 2, 3, 4}, -1), deathstring);
EXPECT_DEATH(gsl::at({1, 2, 3, 4}, 4), deathstring);
}
@@ -120,12 +112,12 @@ static constexpr bool test_constexpr()
const std::array<int, 4>& c_a2 = a2;
for (int i = 0; i < 4; ++i) {
if (&gsl::at(a1, i) != &a1[i]) return false;
if (&gsl::at(c_a1, i) != &a1[i]) return false;
if (&gsl::at(a1, static_cast<std::size_t>(i)) != &a1[i]) return false;
if (&gsl::at(c_a1, static_cast<std::size_t>(i)) != &a1[i]) return false;
// requires C++17:
// if (&gsl::at(a2, i) != &a2[static_cast<std::size_t>(i)]) return false;
if (&gsl::at(c_a2, i) != &c_a2[static_cast<std::size_t>(i)]) return false;
if (gsl::at({1, 2, 3, 4}, i) != i + 1) return false;
if (&gsl::at(c_a2, static_cast<std::size_t>(i)) != &c_a2[static_cast<std::size_t>(i)]) return false;
if (gsl::at({1, 2, 3, 4}, static_cast<std::size_t>(i)) != i + 1) return false;
}
return true;