diff --git a/include/gsl/span b/include/gsl/span index bc278a9..cbc060e 100644 --- a/include/gsl/span +++ b/include/gsl/span @@ -420,18 +420,18 @@ public: constexpr span() noexcept : storage_(nullptr, details::extent_type<0>()) {} - template = 0> - constexpr span(pointer ptr, size_type count) noexcept : storage_(ptr, count) + template = 0> + constexpr explicit span(pointer ptr, size_type count) noexcept : storage_(ptr, count) { Expects(count == Extent); } - template = 0> - constexpr explicit span(pointer ptr, size_type count) noexcept : storage_(ptr, count) + template = 0> + constexpr span(pointer ptr, size_type count) noexcept : storage_(ptr, count) {} template = 0> - constexpr span(pointer firstElem, pointer lastElem) noexcept + constexpr explicit span(pointer firstElem, pointer lastElem) noexcept : storage_(firstElem, static_cast(lastElem - firstElem)) { Expects(lastElem - firstElem == static_cast(Extent)); @@ -519,7 +519,7 @@ public: constexpr span first() const noexcept { Expects(Count <= size()); - return {data(), Count}; + return span(data(), Count); } template @@ -529,7 +529,7 @@ public: constexpr span last() const noexcept { Expects(Count <= size()); - return {data() + (size() - Count), Count}; + return span(data() + (size() - Count), Count); } template @@ -547,7 +547,7 @@ public: constexpr span first(size_type count) const noexcept { Expects(count <= size()); - return span(data(), count); + return {data(), count}; } constexpr span last(size_type count) const noexcept diff --git a/include/gsl/string_span b/include/gsl/string_span index 405eca3..17df7fb 100644 --- a/include/gsl/string_span +++ b/include/gsl/string_span @@ -121,7 +121,7 @@ span ensure_sentinel(T* seq, GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute // TODO: suppress does not work while (static_cast(cur - seq) < max && *cur != Sentinel) ++cur; Ensures(*cur == Sentinel); - return span(seq, static_cast(cur - seq)); + return {seq, static_cast(cur - seq)}; } // diff --git a/tests/span_ext_tests.cpp b/tests/span_ext_tests.cpp index 726d38f..d413e03 100644 --- a/tests/span_ext_tests.cpp +++ b/tests/span_ext_tests.cpp @@ -320,7 +320,7 @@ TEST(span_ext_test, make_span_from_array_constructor) { int arr[] = {1, 2, 3}; - span s1 = span(&arr[0], 2); // shorter + span s1 = {&arr[0], 2}; // shorter span s2 = arr; // longer EXPECT_TRUE(s1 != s2); diff --git a/tests/span_tests.cpp b/tests/span_tests.cpp index a3da486..ae4503e 100644 --- a/tests/span_tests.cpp +++ b/tests/span_tests.cpp @@ -157,7 +157,7 @@ TEST(span_test, from_pointer_length_constructor) for (int i = 0; i < 4; ++i) { { - span s = span(&arr[0], narrow_cast(i)); + span s = {&arr[0], narrow_cast(i)}; EXPECT_TRUE(s.size() == narrow_cast(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(j)]); } { - span s = span(&arr[i], 4 - narrow_cast(i)); + span s = {&arr[i], 4 - narrow_cast(i)}; EXPECT_TRUE(s.size() == 4 - narrow_cast(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 { return span(&arr[1], 2); }; + auto get_temp_span = [&]() -> span { return {&arr[1], 2}; }; auto use_span = [&](span 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 s2 = {&arr[0], 2}; + const span s2(&arr[0], 2); static_cast(s2); } { @@ -1180,7 +1180,7 @@ TEST(span_test, from_array_constructor) #endif { auto f = [&]() { - const span _s4 = {arr2, 2}; + const span _s4(arr2, 2); static_cast(_s4); }; EXPECT_DEATH(f(), deathstring); diff --git a/tests/string_span_tests.cpp b/tests/string_span_tests.cpp index 09e475e..86cf28e 100644 --- a/tests/string_span_tests.cpp +++ b/tests/string_span_tests.cpp @@ -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(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(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(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(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(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(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(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(buf, 1)); }; + const auto workaround_macro = [&]() { const u32zstring_span<> zspan({buf, 1}); }; EXPECT_DEATH(workaround_macro(), deathstring); }