Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 552cd20

Browse files
author
Jordan Maples
committed
addressing most of Casey's comments
1 parent 2085c7a commit 552cd20

5 files changed

Lines changed: 23 additions & 24 deletions

File tree

include/gsl/span

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -420,18 +420,18 @@ public:
420420
constexpr span() noexcept : storage_(nullptr, details::extent_type<0>())
421421
{}
422422

423-
template<std::size_t extent = Extent, std::enable_if_t<extent != gsl::dynamic_extent, int> = 0>
424-
constexpr span(pointer ptr, size_type count) noexcept : storage_(ptr, count)
423+
template<std::size_t extent = Extent, std::enable_if_t<extent != gsl::dynamic_extent, int> = 0>
424+
constexpr explicit span(pointer ptr, size_type count) noexcept : storage_(ptr, count)
425425
{
426426
Expects(count == Extent);
427427
}
428428

429-
template<std::size_t extent = Extent, std::enable_if_t<extent == gsl::dynamic_extent, int> = 0>
430-
constexpr explicit span(pointer ptr, size_type count) noexcept : storage_(ptr, count)
429+
template<std::size_t extent = Extent, std::enable_if_t<extent == gsl::dynamic_extent, int> = 0>
430+
constexpr span(pointer ptr, size_type count) noexcept : storage_(ptr, count)
431431
{}
432432

433433
template<std::size_t extent = Extent, std::enable_if_t<extent != gsl::dynamic_extent, int> = 0>
434-
constexpr span(pointer firstElem, pointer lastElem) noexcept
434+
constexpr explicit span(pointer firstElem, pointer lastElem) noexcept
435435
: storage_(firstElem, static_cast<std::size_t>(lastElem - firstElem))
436436
{
437437
Expects(lastElem - firstElem == static_cast<difference_type>(Extent));
@@ -519,7 +519,7 @@ public:
519519
constexpr span<element_type, Count> first() const noexcept
520520
{
521521
Expects(Count <= size());
522-
return {data(), Count};
522+
return span<element_type, Count>(data(), Count);
523523
}
524524

525525
template <std::size_t Count>
@@ -529,7 +529,7 @@ public:
529529
constexpr span<element_type, Count> last() const noexcept
530530
{
531531
Expects(Count <= size());
532-
return {data() + (size() - Count), Count};
532+
return span<element_type, Count>(data() + (size() - Count), Count);
533533
}
534534

535535
template <std::size_t Offset, std::size_t Count = dynamic_extent>
@@ -547,7 +547,7 @@ public:
547547
constexpr span<element_type, dynamic_extent> first(size_type count) const noexcept
548548
{
549549
Expects(count <= size());
550-
return span<element_type>(data(), count);
550+
return {data(), count};
551551
}
552552

553553
constexpr span<element_type, dynamic_extent> last(size_type count) const noexcept

include/gsl/string_span

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ span<T, dynamic_extent> ensure_sentinel(T* seq,
121121
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute // TODO: suppress does not work
122122
while (static_cast<std::size_t>(cur - seq) < max && *cur != Sentinel) ++cur;
123123
Ensures(*cur == Sentinel);
124-
return span<T>(seq, static_cast<std::size_t>(cur - seq));
124+
return {seq, static_cast<std::size_t>(cur - seq)};
125125
}
126126

127127
//

tests/span_ext_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ TEST(span_ext_test, make_span_from_array_constructor)
320320
{
321321
int arr[] = {1, 2, 3};
322322

323-
span<int> s1 = span<int>(&arr[0], 2); // shorter
323+
span<int> s1 = {&arr[0], 2}; // shorter
324324
span<int> s2 = arr; // longer
325325

326326
EXPECT_TRUE(s1 != s2);

tests/span_tests.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,15 @@ TEST(span_test, from_pointer_length_constructor)
157157
for (int i = 0; i < 4; ++i)
158158
{
159159
{
160-
span<int> s = span<int>(&arr[0], narrow_cast<std::size_t>(i));
160+
span<int> s = {&arr[0], narrow_cast<std::size_t>(i)};
161161
EXPECT_TRUE(s.size() == narrow_cast<std::size_t>(i));
162162
EXPECT_TRUE(s.data() == &arr[0]);
163163
EXPECT_TRUE(s.empty() == (i == 0));
164164
for (int j = 0; j < i; ++j)
165165
EXPECT_TRUE(arr[j] == s[narrow_cast<std::size_t>(j)]);
166166
}
167167
{
168-
span<int> s = span<int>(&arr[i], 4 - narrow_cast<std::size_t>(i));
168+
span<int> s = {&arr[i], 4 - narrow_cast<std::size_t>(i)};
169169
EXPECT_TRUE(s.size() == 4 - narrow_cast<std::size_t>(i));
170170
EXPECT_TRUE(s.data() == &arr[i]);
171171
EXPECT_TRUE(s.empty() == ((4 - i) == 0));
@@ -678,7 +678,7 @@ TEST(span_test, from_array_constructor)
678678
s2 = s1;
679679
EXPECT_TRUE(s2.empty());
680680

681-
auto get_temp_span = [&]() -> span<int> { return span<int>(&arr[1], 2); };
681+
auto get_temp_span = [&]() -> span<int> { return {&arr[1], 2}; };
682682
auto use_span = [&](span<const int> s) {
683683
EXPECT_TRUE(s.size() == 2);
684684
EXPECT_TRUE(s.data() == &arr[1]);
@@ -1144,7 +1144,7 @@ TEST(span_test, from_array_constructor)
11441144

11451145
// you can convert statically
11461146
{
1147-
const span<int, 2> s2 = {&arr[0], 2};
1147+
const span<int, 2> s2(&arr[0], 2);
11481148
static_cast<void>(s2);
11491149
}
11501150
{
@@ -1180,7 +1180,7 @@ TEST(span_test, from_array_constructor)
11801180
#endif
11811181
{
11821182
auto f = [&]() {
1183-
const span<int, 4> _s4 = {arr2, 2};
1183+
const span<int, 4> _s4(arr2, 2);
11841184
static_cast<void>(_s4);
11851185
};
11861186
EXPECT_DEATH(f(), deathstring);

tests/string_span_tests.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ cu16zstring_span<> CreateTempNameU16(u16string_span<> span)
128128
span[last] = u'\0';
129129

130130
auto ret = span.subspan(0, 4);
131-
// return cu16zstring_span<>(ret);
132131
return {ret};
133132
}
134133

@@ -961,7 +960,7 @@ TEST(string_span_tests, zstring)
961960
char buf[1];
962961
buf[0] = '\0';
963962

964-
zstring_span<> zspan(span<char>(buf, 1));
963+
zstring_span<> zspan({buf, 1});
965964

966965
EXPECT_TRUE(generic::strlen(zspan.assume_z()) == 0);
967966
EXPECT_TRUE(zspan.as_string_span().size() == 0);
@@ -973,7 +972,7 @@ TEST(string_span_tests, zstring)
973972
char buf[1];
974973
buf[0] = 'a';
975974

976-
auto workaround_macro = [&]() { const zstring_span<> zspan(span<char>(buf, 1)); };
975+
auto workaround_macro = [&]() { const zstring_span<> zspan({buf, 1}); };
977976
EXPECT_DEATH(workaround_macro(), deathstring);
978977
}
979978

@@ -1002,7 +1001,7 @@ TEST(string_span_tests, wzstring)
10021001
wchar_t buf[1];
10031002
buf[0] = L'\0';
10041003

1005-
wzstring_span<> zspan(span<wchar_t>(buf, 1));
1004+
wzstring_span<> zspan({buf, 1});
10061005

10071006
EXPECT_TRUE(generic::strnlen(zspan.assume_z(), 1) == 0);
10081007
EXPECT_TRUE(zspan.as_string_span().size() == 0);
@@ -1014,7 +1013,7 @@ TEST(string_span_tests, wzstring)
10141013
wchar_t buf[1];
10151014
buf[0] = L'a';
10161015

1017-
const auto workaround_macro = [&]() { const wzstring_span<> zspan(span<wchar_t>(buf, 1)); };
1016+
const auto workaround_macro = [&]() { const wzstring_span<> zspan({buf, 1}); };
10181017
EXPECT_DEATH(workaround_macro(), deathstring);
10191018
}
10201019

@@ -1043,7 +1042,7 @@ TEST(string_span_tests, u16zstring)
10431042
char16_t buf[1];
10441043
buf[0] = L'\0';
10451044

1046-
u16zstring_span<> zspan(span<char16_t>(buf, 1));
1045+
u16zstring_span<> zspan({buf, 1});
10471046

10481047
EXPECT_TRUE(generic::strnlen(zspan.assume_z(), 1) == 0);
10491048
EXPECT_TRUE(zspan.as_string_span().size() == 0);
@@ -1055,7 +1054,7 @@ TEST(string_span_tests, u16zstring)
10551054
char16_t buf[1];
10561055
buf[0] = u'a';
10571056

1058-
const auto workaround_macro = [&]() { const u16zstring_span<> zspan(span<char16_t>(buf, 1)); };
1057+
const auto workaround_macro = [&]() { const u16zstring_span<> zspan({buf, 1}); };
10591058
EXPECT_DEATH(workaround_macro(), deathstring);
10601059
}
10611060

@@ -1084,7 +1083,7 @@ TEST(string_span_tests, u32zstring)
10841083
char32_t buf[1];
10851084
buf[0] = L'\0';
10861085

1087-
u32zstring_span<> zspan(span<char32_t>(buf, 1));
1086+
u32zstring_span<> zspan({buf, 1});
10881087

10891088
EXPECT_TRUE(generic::strnlen(zspan.assume_z(), 1) == 0);
10901089
EXPECT_TRUE(zspan.as_string_span().size() == 0);
@@ -1096,7 +1095,7 @@ TEST(string_span_tests, u32zstring)
10961095
char32_t buf[1];
10971096
buf[0] = u'a';
10981097

1099-
const auto workaround_macro = [&]() { const u32zstring_span<> zspan(span<char32_t>(buf, 1)); };
1098+
const auto workaround_macro = [&]() { const u32zstring_span<> zspan({buf, 1}); };
11001099
EXPECT_DEATH(workaround_macro(), deathstring);
11011100
}
11021101

0 commit comments

Comments
 (0)