mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
update index_type to size_type, fix a couple Expects
This commit is contained in:
parent
61c6ef8d42
commit
5a1e4f3953
@ -143,14 +143,14 @@ namespace details
|
|||||||
constexpr reference operator*() const noexcept
|
constexpr reference operator*() const noexcept
|
||||||
{
|
{
|
||||||
Expects(begin_ && current_ && end_);
|
Expects(begin_ && current_ && end_);
|
||||||
Expects(current_ < end_);
|
Expects(begin_ <= current_ && current_ < end_);
|
||||||
return *current_;
|
return *current_;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr pointer operator->() const noexcept
|
constexpr pointer operator->() const noexcept
|
||||||
{
|
{
|
||||||
Expects(begin_ && current_ && end_);
|
Expects(begin_ && current_ && end_);
|
||||||
Expects(current_ < end_);
|
Expects(begin_ <= current_ && current_ < end_);
|
||||||
return current_;
|
return current_;
|
||||||
}
|
}
|
||||||
constexpr span_iterator& operator++() noexcept
|
constexpr span_iterator& operator++() noexcept
|
||||||
@ -171,7 +171,7 @@ namespace details
|
|||||||
constexpr span_iterator& operator--() noexcept
|
constexpr span_iterator& operator--() noexcept
|
||||||
{
|
{
|
||||||
Expects(begin_ && current_ && end_);
|
Expects(begin_ && current_ && end_);
|
||||||
Expects(current_ > begin_);
|
Expects(begin_ < current_);
|
||||||
--current_;
|
--current_;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -295,7 +295,9 @@ namespace details
|
|||||||
|
|
||||||
constexpr void _Verify_offset(const difference_type n) const noexcept
|
constexpr void _Verify_offset(const difference_type n) const noexcept
|
||||||
{ // test that *this + n is within the range of this call
|
{ // test that *this + n is within the range of this call
|
||||||
Expects( n <= (current_ - begin_) && n <= (end_ - current_));
|
if (n != 0) Expects(begin_ && current_ && end_);
|
||||||
|
if (n > 0) Expects(end_ - current_ >= n);
|
||||||
|
if (n < 0) Expects(current_ - begin_ >= -n);
|
||||||
}
|
}
|
||||||
|
|
||||||
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
|
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
|
||||||
|
@ -105,17 +105,17 @@ TEST(span_test, from_nullptr_size_constructor)
|
|||||||
std::abort();
|
std::abort();
|
||||||
});
|
});
|
||||||
{
|
{
|
||||||
span<int> s{nullptr, narrow_cast<span<int>::index_type>(0)};
|
span<int> s{nullptr, narrow_cast<span<int>::size_type>(0)};
|
||||||
EXPECT_TRUE(s.size() == 0);
|
EXPECT_TRUE(s.size() == 0);
|
||||||
EXPECT_TRUE(s.data() == nullptr);
|
EXPECT_TRUE(s.data() == nullptr);
|
||||||
|
|
||||||
span<int> cs{nullptr, narrow_cast<span<int>::index_type>(0)};
|
span<int> cs{nullptr, narrow_cast<span<int>::size_type>(0)};
|
||||||
EXPECT_TRUE(cs.size() == 0);
|
EXPECT_TRUE(cs.size() == 0);
|
||||||
EXPECT_TRUE(cs.data() == nullptr);
|
EXPECT_TRUE(cs.data() == nullptr);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto workaround_macro = []() {
|
auto workaround_macro = []() {
|
||||||
const span<int, 1> s{nullptr, narrow_cast<span<int>::index_type>(0)};
|
const span<int, 1> s{nullptr, narrow_cast<span<int>::size_type>(0)};
|
||||||
};
|
};
|
||||||
EXPECT_DEATH(workaround_macro(), deathstring);
|
EXPECT_DEATH(workaround_macro(), deathstring);
|
||||||
}
|
}
|
||||||
@ -134,11 +134,11 @@ TEST(span_test, from_nullptr_size_constructor)
|
|||||||
EXPECT_DEATH(const_workaround_macro(), deathstring);
|
EXPECT_DEATH(const_workaround_macro(), deathstring);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
span<int*> s{nullptr, narrow_cast<span<int>::index_type>(0)};
|
span<int*> s{nullptr, narrow_cast<span<int>::size_type>(0)};
|
||||||
EXPECT_TRUE(s.size() == 0);
|
EXPECT_TRUE(s.size() == 0);
|
||||||
EXPECT_TRUE(s.data() == nullptr);
|
EXPECT_TRUE(s.data() == nullptr);
|
||||||
|
|
||||||
span<const int*> cs{nullptr, narrow_cast<span<int>::index_type>(0)};
|
span<const int*> cs{nullptr, narrow_cast<span<int>::size_type>(0)};
|
||||||
EXPECT_TRUE(cs.size() == 0);
|
EXPECT_TRUE(cs.size() == 0);
|
||||||
EXPECT_TRUE(cs.data() == nullptr);
|
EXPECT_TRUE(cs.data() == nullptr);
|
||||||
}
|
}
|
||||||
@ -193,7 +193,7 @@ TEST(span_test, from_pointer_length_constructor)
|
|||||||
|
|
||||||
{
|
{
|
||||||
int* p = nullptr;
|
int* p = nullptr;
|
||||||
span<int> s{p, narrow_cast<span<int>::index_type>(0)};
|
span<int> s{p, narrow_cast<span<int>::size_type>(0)};
|
||||||
EXPECT_TRUE(s.size() == 0);
|
EXPECT_TRUE(s.size() == 0);
|
||||||
EXPECT_TRUE(s.data() == nullptr);
|
EXPECT_TRUE(s.data() == nullptr);
|
||||||
}
|
}
|
||||||
@ -214,7 +214,7 @@ TEST(span_test, from_pointer_length_constructor)
|
|||||||
|
|
||||||
{
|
{
|
||||||
int* p = nullptr;
|
int* p = nullptr;
|
||||||
auto s = make_span(p, narrow_cast<span<int>::index_type>(0));
|
auto s = make_span(p, narrow_cast<span<int>::size_type>(0));
|
||||||
EXPECT_TRUE(s.size() == 0);
|
EXPECT_TRUE(s.size() == 0);
|
||||||
EXPECT_TRUE(s.data() == nullptr);
|
EXPECT_TRUE(s.data() == nullptr);
|
||||||
}
|
}
|
||||||
|
@ -163,14 +163,14 @@ TEST(string_span_tests, TestConstructFromStdString)
|
|||||||
{
|
{
|
||||||
std::string s = "Hello there world";
|
std::string s = "Hello there world";
|
||||||
cstring_span<> v = s;
|
cstring_span<> v = s;
|
||||||
EXPECT_TRUE(v.length() == static_cast<cstring_span<>::index_type>(s.length()));
|
EXPECT_TRUE(v.length() == static_cast<cstring_span<>::size_type>(s.length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(string_span_tests, TestConstructFromStdVector)
|
TEST(string_span_tests, TestConstructFromStdVector)
|
||||||
{
|
{
|
||||||
std::vector<char> vec(5, 'h');
|
std::vector<char> vec(5, 'h');
|
||||||
string_span<> v{vec};
|
string_span<> v{vec};
|
||||||
EXPECT_TRUE(v.length() == static_cast<string_span<>::index_type>(vec.size()));
|
EXPECT_TRUE(v.length() == static_cast<string_span<>::size_type>(vec.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(string_span_tests, TestStackArrayConstruction)
|
TEST(string_span_tests, TestStackArrayConstruction)
|
||||||
@ -232,7 +232,7 @@ TEST(string_span_tests, TestToString)
|
|||||||
char stack_string[] = "Hello";
|
char stack_string[] = "Hello";
|
||||||
cstring_span<> v = ensure_z(stack_string);
|
cstring_span<> v = ensure_z(stack_string);
|
||||||
auto s2 = gsl::to_string(v);
|
auto s2 = gsl::to_string(v);
|
||||||
EXPECT_TRUE(static_cast<cstring_span<>::index_type>(s2.length()) == v.length());
|
EXPECT_TRUE(static_cast<cstring_span<>::size_type>(s2.length()) == v.length());
|
||||||
EXPECT_TRUE(s2.length() == static_cast<size_t>(5));
|
EXPECT_TRUE(s2.length() == static_cast<size_t>(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,7 +245,7 @@ TEST(string_span_tests, TestToBasicString)
|
|||||||
char stack_string[] = "Hello";
|
char stack_string[] = "Hello";
|
||||||
cstring_span<> v = ensure_z(stack_string);
|
cstring_span<> v = ensure_z(stack_string);
|
||||||
auto s2 = gsl::to_basic_string<char, std::char_traits<char>, ::std::allocator<char>>(v);
|
auto s2 = gsl::to_basic_string<char, std::char_traits<char>, ::std::allocator<char>>(v);
|
||||||
EXPECT_TRUE(static_cast<cstring_span<>::index_type>(s2.length()) == v.length());
|
EXPECT_TRUE(static_cast<cstring_span<>::size_type>(s2.length()) == v.length());
|
||||||
EXPECT_TRUE(s2.length() == static_cast<size_t>(5));
|
EXPECT_TRUE(s2.length() == static_cast<size_t>(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user