Make is_default_constructible work for spans.

This commit is contained in:
Casey Carter 2017-01-28 00:08:48 -08:00 committed by Neil MacIntosh
parent f93d325495
commit 96eaf274f8
2 changed files with 20 additions and 9 deletions

View File

@ -359,6 +359,10 @@ public:
constexpr static const index_type extent = Extent;
// [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(std::nullptr_t) noexcept : span() {}

View File

@ -1557,6 +1557,13 @@ SUITE(span_tests)
span<int> s{arr};
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(); }