Extend docs and tests for span ctor (#1096)

This commit is contained in:
Werner Henze 2023-02-22 00:46:40 +01:00 committed by GitHub
parent 9851b94d7e
commit 7a297d4283
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -485,6 +485,9 @@ constexpr span(const span<OtherElementType, OtherExtent>& other) noexcept;
Constructs a `span` from another `span`. This constructor is available if `OtherExtent == Extent || Extent ==`[`gsl::dynamic_extent`](#user-content-H-span_ext-dynamic_extent)` || OtherExtent ==`[`gsl::dynamic_extent`](#user-content-H-span_ext-dynamic_extent) Constructs a `span` from another `span`. This constructor is available if `OtherExtent == Extent || Extent ==`[`gsl::dynamic_extent`](#user-content-H-span_ext-dynamic_extent)` || OtherExtent ==`[`gsl::dynamic_extent`](#user-content-H-span_ext-dynamic_extent)
and if `ElementType` and `OtherElementType` are compatible. and if `ElementType` and `OtherElementType` are compatible.
If `Extent !=`[`gsl::dynamic_extent`](#user-content-H-span_ext-dynamic_extent) and `OtherExtent ==`[`gsl::dynamic_extent`](#user-content-H-span_ext-dynamic_extent),
then the constructor [`Expects`](#user-content-H-assert-expects) that `other.size() == Extent`.
```cpp ```cpp
constexpr span& operator=(const span& other) noexcept = default; constexpr span& operator=(const span& other) noexcept = default;
``` ```

View File

@ -681,6 +681,13 @@ TEST(span_test, from_convertible_span_constructor)
static_cast<void>(avcd); static_cast<void>(avcd);
} }
{
std::array<DerivedClass, 2> arr{};
span<DerivedClass> avd{arr};
using T = span<const DerivedClass, 1>;
EXPECT_DEATH(T{avd}, expected);
}
{ {
std::array<DerivedClass, 1> arr{}; std::array<DerivedClass, 1> arr{};
span<DerivedClass> avd{arr}; span<DerivedClass> avd{arr};