365 lines
12 KiB
Markdown
365 lines
12 KiB
Markdown
[span.cons]
|
||
|
||
# 23 Containers library [[containers]](./#containers)
|
||
|
||
## 23.7 Views [[views]](views#span.cons)
|
||
|
||
### 23.7.2 Contiguous access [[views.contiguous]](views.contiguous#span.cons)
|
||
|
||
#### 23.7.2.2 Class template span [[views.span]](views.span#span.cons)
|
||
|
||
#### 23.7.2.2.2 Constructors, copy, and assignment [span.cons]
|
||
|
||
[ð](#lib:span,constructor)
|
||
|
||
`constexpr span() noexcept;
|
||
`
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20344)
|
||
|
||
*Constraints*: Extent == dynamic_extent || Extent == 0 is true[.](#1.sentence-1)
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20348)
|
||
|
||
*Postconditions*: size() == 0 && data() == nullptr[.](#2.sentence-1)
|
||
|
||
[ð](#lib:span,constructor_)
|
||
|
||
`template<class It>
|
||
constexpr explicit(extent != dynamic_extent) span(It first, size_type count);
|
||
`
|
||
|
||
[3](#3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20361)
|
||
|
||
*Constraints*: Let U be remove_reference_t<iter_reference_t<It>>[.](#3.sentence-1)
|
||
|
||
- [(3.1)](#3.1)
|
||
|
||
It satisfies [contiguous_iterator](iterator.concept.contiguous#concept:contiguous_iterator "24.3.4.14 Concept contiguous_iterator [iterator.concept.contiguous]")[.](#3.1.sentence-1)
|
||
|
||
- [(3.2)](#3.2)
|
||
|
||
is_convertible_v<U(*)[], element_type(*)[]> is true[.](#3.2.sentence-1)
|
||
[*Note [1](#note-1)*:
|
||
The intent is to allow only qualification conversions
|
||
of the iterator reference type to element_type[.](#3.2.sentence-2)
|
||
â *end note*]
|
||
|
||
[4](#4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20374)
|
||
|
||
*Preconditions*:
|
||
|
||
- [(4.1)](#4.1)
|
||
|
||
[first, first + count) is a valid range[.](#4.1.sentence-1)
|
||
|
||
- [(4.2)](#4.2)
|
||
|
||
It models [contiguous_iterator](iterator.concept.contiguous#concept:contiguous_iterator "24.3.4.14 Concept contiguous_iterator [iterator.concept.contiguous]")[.](#4.2.sentence-1)
|
||
|
||
[5](#5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20381)
|
||
|
||
*Hardened preconditions*: If extent is not equal to dynamic_extent,
|
||
then count == extent is true[.](#5.sentence-1)
|
||
|
||
[6](#6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20386)
|
||
|
||
*Effects*: Initializes *data_* with to_address(first) and*size_* with count[.](#6.sentence-1)
|
||
|
||
[7](#7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20391)
|
||
|
||
*Throws*: Nothing[.](#7.sentence-1)
|
||
|
||
[ð](#lib:span,constructor__)
|
||
|
||
`template<class It, class End>
|
||
constexpr explicit(extent != dynamic_extent) span(It first, End last);
|
||
`
|
||
|
||
[8](#8)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20403)
|
||
|
||
*Constraints*: Let U be remove_reference_t<iter_reference_t<It>>[.](#8.sentence-1)
|
||
|
||
- [(8.1)](#8.1)
|
||
|
||
is_convertible_v<U(*)[], element_type(*)[]> is true[.](#8.1.sentence-1)
|
||
[*Note [2](#note-2)*:
|
||
The intent is to allow only qualification conversions
|
||
of the iterator reference type to element_type[.](#8.1.sentence-2)
|
||
â *end note*]
|
||
|
||
- [(8.2)](#8.2)
|
||
|
||
It satisfies [contiguous_iterator](iterator.concept.contiguous#concept:contiguous_iterator "24.3.4.14 Concept contiguous_iterator [iterator.concept.contiguous]")[.](#8.2.sentence-1)
|
||
|
||
- [(8.3)](#8.3)
|
||
|
||
End satisfies [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<It>[.](#8.3.sentence-1)
|
||
|
||
- [(8.4)](#8.4)
|
||
|
||
is_convertible_v<End, size_t> is false[.](#8.4.sentence-1)
|
||
|
||
[9](#9)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20418)
|
||
|
||
*Preconditions*:
|
||
|
||
- [(9.1)](#9.1)
|
||
|
||
[first, last) is a valid range[.](#9.1.sentence-1)
|
||
|
||
- [(9.2)](#9.2)
|
||
|
||
It models [contiguous_iterator](iterator.concept.contiguous#concept:contiguous_iterator "24.3.4.14 Concept contiguous_iterator [iterator.concept.contiguous]")[.](#9.2.sentence-1)
|
||
|
||
- [(9.3)](#9.3)
|
||
|
||
End models [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<It>[.](#9.3.sentence-1)
|
||
|
||
[10](#10)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20426)
|
||
|
||
*Hardened preconditions*: If extent is not equal to dynamic_extent,
|
||
then (last - first) == extent is true[.](#10.sentence-1)
|
||
|
||
[11](#11)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20431)
|
||
|
||
*Effects*: Initializes *data_* with to_address(first) and*size_* with last - first[.](#11.sentence-1)
|
||
|
||
[12](#12)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20436)
|
||
|
||
*Throws*: When and what last - first throws[.](#12.sentence-1)
|
||
|
||
[ð](#lib:span,constructor___)
|
||
|
||
`template<size_t N> constexpr span(type_identity_t<element_type> (&arr)[N]) noexcept;
|
||
template<class T, size_t N> constexpr span(array<T, N>& arr) noexcept;
|
||
template<class T, size_t N> constexpr span(const array<T, N>& arr) noexcept;
|
||
`
|
||
|
||
[13](#13)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20449)
|
||
|
||
*Constraints*: Let U be remove_pointer_t<decltype(std::data(arr))>[.](#13.sentence-1)
|
||
|
||
- [(13.1)](#13.1)
|
||
|
||
extent == dynamic_extent || N == extent is true, and
|
||
|
||
- [(13.2)](#13.2)
|
||
|
||
is_convertible_v<U(*)[], element_type(*)[]> is true. [*Note [3](#note-3)*:
|
||
The intent is to allow only qualification conversions
|
||
of the array element type to element_type[.](#13.2.sentence-2)
|
||
â *end note*]
|
||
|
||
[14](#14)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20461)
|
||
|
||
*Effects*: Constructs a span that is a view over the supplied array[.](#14.sentence-1)
|
||
|
||
[*Note [4](#note-4)*:
|
||
|
||
type_identity_t affects class template argument deduction[.](#14.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
[15](#15)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20468)
|
||
|
||
*Postconditions*: size() == N && data() == std::data(arr) is true[.](#15.sentence-1)
|
||
|
||
[ð](#lib:span,constructor____)
|
||
|
||
`template<class R> constexpr explicit(extent != dynamic_extent) span(R&& r);
|
||
`
|
||
|
||
[16](#16)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20479)
|
||
|
||
*Constraints*: Let U be remove_reference_t<ranges::range_reference_t<R>>[.](#16.sentence-1)
|
||
|
||
- [(16.1)](#16.1)
|
||
|
||
R satisfies ranges::[contiguous_range](range.refinements#concept:contiguous_range "25.4.6 Other range refinements [range.refinements]") and ranges::[sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]")[.](#16.1.sentence-1)
|
||
|
||
- [(16.2)](#16.2)
|
||
|
||
Either R satisfies ranges::[borrowed_range](range.range#concept:borrowed_range "25.4.2 Ranges [range.range]") oris_const_v<element_type> is true[.](#16.2.sentence-1)
|
||
|
||
- [(16.3)](#16.3)
|
||
|
||
remove_cvref_t<R> is not a specialization of span[.](#16.3.sentence-1)
|
||
|
||
- [(16.4)](#16.4)
|
||
|
||
remove_cvref_t<R> is not a specialization of array[.](#16.4.sentence-1)
|
||
|
||
- [(16.5)](#16.5)
|
||
|
||
is_array_v<remove_cvref_t<R>> is false[.](#16.5.sentence-1)
|
||
|
||
- [(16.6)](#16.6)
|
||
|
||
is_convertible_v<U(*)[], element_type(*)[]> is true[.](#16.6.sentence-1)
|
||
[*Note [5](#note-5)*:
|
||
The intent is to allow only qualification conversions
|
||
of the range reference type to element_type[.](#16.6.sentence-2)
|
||
â *end note*]
|
||
|
||
[17](#17)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20498)
|
||
|
||
*Preconditions*:
|
||
|
||
- [(17.1)](#17.1)
|
||
|
||
R models ranges::[contiguous_range](range.refinements#concept:contiguous_range "25.4.6 Other range refinements [range.refinements]") andranges::[sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]")[.](#17.1.sentence-1)
|
||
|
||
- [(17.2)](#17.2)
|
||
|
||
If is_const_v<element_type> is false,R models ranges::[borrowed_range](range.range#concept:borrowed_range "25.4.2 Ranges [range.range]")[.](#17.2.sentence-1)
|
||
|
||
[18](#18)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20507)
|
||
|
||
*Hardened preconditions*: If extent is not equal to dynamic_extent,
|
||
then ranges::size(r) == extent is true[.](#18.sentence-1)
|
||
|
||
[19](#19)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20512)
|
||
|
||
*Effects*: Initializes *data_* with ranges::data(r) and*size_* with ranges::size(r)[.](#19.sentence-1)
|
||
|
||
[20](#20)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20517)
|
||
|
||
*Throws*: What and when ranges::data(r) and ranges::size(r) throw[.](#20.sentence-1)
|
||
|
||
[ð](#lib:span,constructor_____)
|
||
|
||
`constexpr explicit(extent != dynamic_extent) span(std::initializer_list<value_type> il);
|
||
`
|
||
|
||
[21](#21)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20528)
|
||
|
||
*Constraints*: is_const_v<element_type> is true[.](#21.sentence-1)
|
||
|
||
[22](#22)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20532)
|
||
|
||
*Hardened preconditions*: If extent is not equal to dynamic_extent,
|
||
then il.size() == extent is true[.](#22.sentence-1)
|
||
|
||
[23](#23)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20537)
|
||
|
||
*Effects*: Initializes *data_* with il.begin() and*size_* with il.size()[.](#23.sentence-1)
|
||
|
||
[ð](#lib:span,constructor______)
|
||
|
||
`constexpr span(const span& other) noexcept = default;
|
||
`
|
||
|
||
[24](#24)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20549)
|
||
|
||
*Postconditions*: other.size() == size() && other.data() == data()[.](#24.sentence-1)
|
||
|
||
[ð](#lib:span,constructor_______)
|
||
|
||
`template<class OtherElementType, size_t OtherExtent>
|
||
constexpr explicit(see below) span(const span<OtherElementType, OtherExtent>& s) noexcept;
|
||
`
|
||
|
||
[25](#25)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20561)
|
||
|
||
*Constraints*:
|
||
|
||
- [(25.1)](#25.1)
|
||
|
||
extent == dynamic_extent || OtherExtent == dynamic_extent || extent == OtherExtent is true, and
|
||
|
||
- [(25.2)](#25.2)
|
||
|
||
is_convertible_v<OtherElementType(*)[], element_type(*)[]> is true[.](#25.sentence-1)
|
||
[*Note [6](#note-6)*:
|
||
The intent is to allow only qualification conversions
|
||
of the OtherElementType to element_type[.](#25.2.sentence-2)
|
||
â *end note*]
|
||
|
||
[26](#26)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20572)
|
||
|
||
*Hardened preconditions*: If extent is not equal to dynamic_extent,
|
||
then s.size() == extent is true[.](#26.sentence-1)
|
||
|
||
[27](#27)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20577)
|
||
|
||
*Effects*: Constructs a span that is a view over the range
|
||
[s.data(), s.data() + s.size())[.](#27.sentence-1)
|
||
|
||
[28](#28)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20582)
|
||
|
||
*Postconditions*: size() == s.size() && data() == s.data()[.](#28.sentence-1)
|
||
|
||
[29](#29)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20586)
|
||
|
||
*Remarks*: The expression inside explicit is equivalent to:extent != dynamic_extent && OtherExtent == dynamic_extent
|
||
|
||
[ð](#lib:operator=,span)
|
||
|
||
`constexpr span& operator=(const span& other) noexcept = default;
|
||
`
|
||
|
||
[30](#30)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20600)
|
||
|
||
*Postconditions*: size() == other.size() && data() == other.data()[.](#30.sentence-1)
|