addressing most of Casey's comments

This commit is contained in:
Jordan Maples 2020-05-20 10:59:57 -07:00
parent 2085c7acde
commit 552cd20472
5 changed files with 23 additions and 24 deletions

View File

@ -421,17 +421,17 @@ public:
{}
template<std::size_t extent = Extent, std::enable_if_t<extent != gsl::dynamic_extent, int> = 0>
constexpr span(pointer ptr, size_type count) noexcept : storage_(ptr, count)
constexpr explicit span(pointer ptr, size_type count) noexcept : storage_(ptr, count)
{
Expects(count == Extent);
}
template<std::size_t extent = Extent, std::enable_if_t<extent == gsl::dynamic_extent, int> = 0>
constexpr explicit span(pointer ptr, size_type count) noexcept : storage_(ptr, count)
constexpr span(pointer ptr, size_type count) noexcept : storage_(ptr, count)
{}
template<std::size_t extent = Extent, std::enable_if_t<extent != gsl::dynamic_extent, int> = 0>
constexpr span(pointer firstElem, pointer lastElem) noexcept
constexpr explicit span(pointer firstElem, pointer lastElem) noexcept
: storage_(firstElem, static_cast<std::size_t>(lastElem - firstElem))
{
Expects(lastElem - firstElem == static_cast<difference_type>(Extent));
@ -519,7 +519,7 @@ public:
constexpr span<element_type, Count> first() const noexcept
{
Expects(Count <= size());
return {data(), Count};
return span<element_type, Count>(data(), Count);
}
template <std::size_t Count>
@ -529,7 +529,7 @@ public:
constexpr span<element_type, Count> last() const noexcept
{
Expects(Count <= size());
return {data() + (size() - Count), Count};
return span<element_type, Count>(data() + (size() - Count), Count);
}
template <std::size_t Offset, std::size_t Count = dynamic_extent>
@ -547,7 +547,7 @@ public:
constexpr span<element_type, dynamic_extent> first(size_type count) const noexcept
{
Expects(count <= size());
return span<element_type>(data(), count);
return {data(), count};
}
constexpr span<element_type, dynamic_extent> last(size_type count) const noexcept

View File

@ -121,7 +121,7 @@ span<T, dynamic_extent> ensure_sentinel(T* seq,
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute // TODO: suppress does not work
while (static_cast<std::size_t>(cur - seq) < max && *cur != Sentinel) ++cur;
Ensures(*cur == Sentinel);
return span<T>(seq, static_cast<std::size_t>(cur - seq));
return {seq, static_cast<std::size_t>(cur - seq)};
}
//

View File

@ -320,7 +320,7 @@ TEST(span_ext_test, make_span_from_array_constructor)
{
int arr[] = {1, 2, 3};
span<int> s1 = span<int>(&arr[0], 2); // shorter
span<int> s1 = {&arr[0], 2}; // shorter
span<int> s2 = arr; // longer
EXPECT_TRUE(s1 != s2);

View File

@ -157,7 +157,7 @@ TEST(span_test, from_pointer_length_constructor)
for (int i = 0; i < 4; ++i)
{
{
span<int> s = span<int>(&arr[0], narrow_cast<std::size_t>(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));
@ -165,7 +165,7 @@ TEST(span_test, from_pointer_length_constructor)
EXPECT_TRUE(arr[j] == s[narrow_cast<std::size_t>(j)]);
}
{
span<int> s = span<int>(&arr[i], 4 - narrow_cast<std::size_t>(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));
@ -678,7 +678,7 @@ TEST(span_test, from_array_constructor)
s2 = s1;
EXPECT_TRUE(s2.empty());
auto get_temp_span = [&]() -> span<int> { return span<int>(&arr[1], 2); };
auto get_temp_span = [&]() -> span<int> { return {&arr[1], 2}; };
auto use_span = [&](span<const int> s) {
EXPECT_TRUE(s.size() == 2);
EXPECT_TRUE(s.data() == &arr[1]);
@ -1144,7 +1144,7 @@ TEST(span_test, from_array_constructor)
// you can convert statically
{
const span<int, 2> s2 = {&arr[0], 2};
const span<int, 2> s2(&arr[0], 2);
static_cast<void>(s2);
}
{
@ -1180,7 +1180,7 @@ TEST(span_test, from_array_constructor)
#endif
{
auto f = [&]() {
const span<int, 4> _s4 = {arr2, 2};
const span<int, 4> _s4(arr2, 2);
static_cast<void>(_s4);
};
EXPECT_DEATH(f(), deathstring);

View File

@ -128,7 +128,6 @@ cu16zstring_span<> CreateTempNameU16(u16string_span<> span)
span[last] = u'\0';
auto ret = span.subspan(0, 4);
// return cu16zstring_span<>(ret);
return {ret};
}
@ -961,7 +960,7 @@ TEST(string_span_tests, zstring)
char buf[1];
buf[0] = '\0';
zstring_span<> zspan(span<char>(buf, 1));
zstring_span<> zspan({buf, 1});
EXPECT_TRUE(generic::strlen(zspan.assume_z()) == 0);
EXPECT_TRUE(zspan.as_string_span().size() == 0);
@ -973,7 +972,7 @@ TEST(string_span_tests, zstring)
char buf[1];
buf[0] = 'a';
auto workaround_macro = [&]() { const zstring_span<> zspan(span<char>(buf, 1)); };
auto workaround_macro = [&]() { const zstring_span<> zspan({buf, 1}); };
EXPECT_DEATH(workaround_macro(), deathstring);
}
@ -1002,7 +1001,7 @@ TEST(string_span_tests, wzstring)
wchar_t buf[1];
buf[0] = L'\0';
wzstring_span<> zspan(span<wchar_t>(buf, 1));
wzstring_span<> zspan({buf, 1});
EXPECT_TRUE(generic::strnlen(zspan.assume_z(), 1) == 0);
EXPECT_TRUE(zspan.as_string_span().size() == 0);
@ -1014,7 +1013,7 @@ TEST(string_span_tests, wzstring)
wchar_t buf[1];
buf[0] = L'a';
const auto workaround_macro = [&]() { const wzstring_span<> zspan(span<wchar_t>(buf, 1)); };
const auto workaround_macro = [&]() { const wzstring_span<> zspan({buf, 1}); };
EXPECT_DEATH(workaround_macro(), deathstring);
}
@ -1043,7 +1042,7 @@ TEST(string_span_tests, u16zstring)
char16_t buf[1];
buf[0] = L'\0';
u16zstring_span<> zspan(span<char16_t>(buf, 1));
u16zstring_span<> zspan({buf, 1});
EXPECT_TRUE(generic::strnlen(zspan.assume_z(), 1) == 0);
EXPECT_TRUE(zspan.as_string_span().size() == 0);
@ -1055,7 +1054,7 @@ TEST(string_span_tests, u16zstring)
char16_t buf[1];
buf[0] = u'a';
const auto workaround_macro = [&]() { const u16zstring_span<> zspan(span<char16_t>(buf, 1)); };
const auto workaround_macro = [&]() { const u16zstring_span<> zspan({buf, 1}); };
EXPECT_DEATH(workaround_macro(), deathstring);
}
@ -1084,7 +1083,7 @@ TEST(string_span_tests, u32zstring)
char32_t buf[1];
buf[0] = L'\0';
u32zstring_span<> zspan(span<char32_t>(buf, 1));
u32zstring_span<> zspan({buf, 1});
EXPECT_TRUE(generic::strnlen(zspan.assume_z(), 1) == 0);
EXPECT_TRUE(zspan.as_string_span().size() == 0);
@ -1096,7 +1095,7 @@ TEST(string_span_tests, u32zstring)
char32_t buf[1];
buf[0] = u'a';
const auto workaround_macro = [&]() { const u32zstring_span<> zspan(span<char32_t>(buf, 1)); };
const auto workaround_macro = [&]() { const u32zstring_span<> zspan({buf, 1}); };
EXPECT_DEATH(workaround_macro(), deathstring);
}