mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Make is_default_constructible work for spans.
This commit is contained in:
parent
f93d325495
commit
96eaf274f8
6
gsl/span
6
gsl/span
@ -308,7 +308,7 @@ namespace details
|
|||||||
constexpr extent_type() noexcept {}
|
constexpr extent_type() noexcept {}
|
||||||
|
|
||||||
template <index_type Other>
|
template <index_type Other>
|
||||||
constexpr extent_type(extent_type<Other> ext)
|
constexpr extent_type(extent_type<Other> ext)
|
||||||
{
|
{
|
||||||
static_assert(Other == Ext || Other == dynamic_extent,
|
static_assert(Other == Ext || Other == dynamic_extent,
|
||||||
"Mismatch between fixed-size extent and size of initializing data.");
|
"Mismatch between fixed-size extent and size of initializing data.");
|
||||||
@ -359,6 +359,10 @@ public:
|
|||||||
constexpr static const index_type extent = Extent;
|
constexpr static const index_type extent = Extent;
|
||||||
|
|
||||||
// [span.cons], span constructors, copy, assignment, and destructor
|
// [span.cons], span constructors, copy, assignment, and destructor
|
||||||
|
template <bool Dependent = false,
|
||||||
|
// "Dependent" is needed to make "std::enable_if_t<Dependent || Extent <= 0>" SFINAE,
|
||||||
|
// since "std::enable_if_t<Extent <= 0>" is ill-formed when Extent is greater than 0.
|
||||||
|
class = std::enable_if_t<(Dependent || Extent <= 0)>>
|
||||||
constexpr span() noexcept : storage_(nullptr, details::extent_type<0>()) {}
|
constexpr span() noexcept : storage_(nullptr, details::extent_type<0>()) {}
|
||||||
|
|
||||||
constexpr span(std::nullptr_t) noexcept : span() {}
|
constexpr span(std::nullptr_t) noexcept : span() {}
|
||||||
|
@ -149,7 +149,7 @@ SUITE(span_tests)
|
|||||||
|
|
||||||
{
|
{
|
||||||
auto workaround_macro = []() { span<int, 1> s{ nullptr, static_cast<span<int>::index_type>(0) }; };
|
auto workaround_macro = []() { span<int, 1> s{ nullptr, static_cast<span<int>::index_type>(0) }; };
|
||||||
CHECK_THROW(workaround_macro(), fail_fast);
|
CHECK_THROW(workaround_macro(), fail_fast);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -680,7 +680,7 @@ SUITE(span_tests)
|
|||||||
{
|
{
|
||||||
#ifdef CONFIRM_COMPILATION_ERRORS
|
#ifdef CONFIRM_COMPILATION_ERRORS
|
||||||
span<char> s{cstr};
|
span<char> s{cstr};
|
||||||
#endif
|
#endif
|
||||||
span<const char> cs{cstr};
|
span<const char> cs{cstr};
|
||||||
CHECK(cs.size() == narrow_cast<std::ptrdiff_t>(cstr.size()) &&
|
CHECK(cs.size() == narrow_cast<std::ptrdiff_t>(cstr.size()) &&
|
||||||
cs.data() == cstr.data());
|
cs.data() == cstr.data());
|
||||||
@ -691,7 +691,7 @@ SUITE(span_tests)
|
|||||||
auto get_temp_vector = []() -> std::vector<int> { return {}; };
|
auto get_temp_vector = []() -> std::vector<int> { return {}; };
|
||||||
auto use_span = [](span<int> s) { static_cast<void>(s); };
|
auto use_span = [](span<int> s) { static_cast<void>(s); };
|
||||||
use_span(get_temp_vector());
|
use_span(get_temp_vector());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -705,7 +705,7 @@ SUITE(span_tests)
|
|||||||
auto get_temp_string = []() -> std::string { return{}; };
|
auto get_temp_string = []() -> std::string { return{}; };
|
||||||
auto use_span = [](span<char> s) { static_cast<void>(s); };
|
auto use_span = [](span<char> s) { static_cast<void>(s); };
|
||||||
use_span(get_temp_string());
|
use_span(get_temp_string());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -866,7 +866,7 @@ SUITE(span_tests)
|
|||||||
span<int, 5> av = arr;
|
span<int, 5> av = arr;
|
||||||
#ifdef CONFIRM_COMPILATION_ERRORS
|
#ifdef CONFIRM_COMPILATION_ERRORS
|
||||||
CHECK(av.last<6>().length() == 6);
|
CHECK(av.last<6>().length() == 6);
|
||||||
#endif
|
#endif
|
||||||
CHECK_THROW(av.last(6).length(), fail_fast);
|
CHECK_THROW(av.last(6).length(), fail_fast);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1098,7 +1098,7 @@ SUITE(span_tests)
|
|||||||
CHECK(beyond - first == 4);
|
CHECK(beyond - first == 4);
|
||||||
CHECK(first - first == 0);
|
CHECK(first - first == 0);
|
||||||
CHECK(beyond - beyond == 0);
|
CHECK(beyond - beyond == 0);
|
||||||
|
|
||||||
++it;
|
++it;
|
||||||
CHECK(it - first == 1);
|
CHECK(it - first == 1);
|
||||||
CHECK(*it == 2);
|
CHECK(*it == 2);
|
||||||
@ -1515,7 +1515,7 @@ SUITE(span_tests)
|
|||||||
auto f = [&]() {
|
auto f = [&]() {
|
||||||
span<int, 4> _s4 = {arr2, 2};
|
span<int, 4> _s4 = {arr2, 2};
|
||||||
static_cast<void>(_s4);
|
static_cast<void>(_s4);
|
||||||
};
|
};
|
||||||
CHECK_THROW(f(), fail_fast);
|
CHECK_THROW(f(), fail_fast);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1523,7 +1523,7 @@ SUITE(span_tests)
|
|||||||
span<int> av = arr2;
|
span<int> av = arr2;
|
||||||
auto f = [&]() {
|
auto f = [&]() {
|
||||||
span<int, 4> _s4 = av;
|
span<int, 4> _s4 = av;
|
||||||
static_cast<void>(_s4);
|
static_cast<void>(_s4);
|
||||||
};
|
};
|
||||||
CHECK_THROW(f(), fail_fast);
|
CHECK_THROW(f(), fail_fast);
|
||||||
}
|
}
|
||||||
@ -1557,6 +1557,13 @@ SUITE(span_tests)
|
|||||||
span<int> s{arr};
|
span<int> s{arr};
|
||||||
CHECK(at(s,0) == 1 && at(s,1) == 2);
|
CHECK(at(s,0) == 1 && at(s,1) == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(default_constructible)
|
||||||
|
{
|
||||||
|
CHECK((std::is_default_constructible<span<int>>::value));
|
||||||
|
CHECK((std::is_default_constructible<span<int, 0>>::value));
|
||||||
|
CHECK((!std::is_default_constructible<span<int, 42>>::value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int, const char* []) { return UnitTest::RunAllTests(); }
|
int main(int, const char* []) { return UnitTest::RunAllTests(); }
|
||||||
|
Loading…
Reference in New Issue
Block a user