Span can be constructed from empty std::array safely (#686)

* Span std::array c'tor uses arr.data() instead of &arr[0]
- Fixes runtime issues when constructing from an empty std::array

* Construct span with std::data if C++17 detected

* Specialize span c'tor for std::array of length 0, set storage to nullptr
This commit is contained in:
Dave Hill
2018-11-05 15:39:41 -08:00
committed by Anna Gringauze
parent 2bf9f137a6
commit c02ddae4bc
2 changed files with 26 additions and 10 deletions
+7 -1
View File
@@ -452,7 +452,13 @@ TEST_CASE("from_std_array_constructor")
CHECK((cs.size() == narrow_cast<ptrdiff_t>(arr.size()) && cs.data() == arr.data()));
}
std::array<AddressOverloaded, 4> ao_arr{};
{
std::array<int, 0> empty_arr{};
span<int> s{empty_arr};
CHECK((s.size() == 0 && s.empty()));
}
std::array<AddressOverloaded, 4> ao_arr{};
{
span<AddressOverloaded, 4> fs{ao_arr};