Files
cppdraft_translate/cppdraft/span/cons.md
2025-10-25 03:02:53 +03:00

12 KiB
Raw Blame History

[span.cons]

23 Containers library [containers]

23.7 Views [views]

23.7.2 Contiguous access [views.contiguous]

23.7.2.2 Class template span [views.span]

23.7.2.2.2 Constructors, copy, and assignment [span.cons]

🔗

constexpr span() noexcept;

1

#

Constraints: Extent == dynamic_extent || Extent == 0 is true.

2

#

Postconditions: size() == 0 && data() == nullptr.

🔗

template<class It> constexpr explicit(extent != dynamic_extent) span(It first, size_type count);

3

#

Constraints: Let U be remove_reference_t<iter_reference_t>.

  • (3.1)

    It satisfies contiguous_iterator.

  • (3.2)

    is_convertible_v<U()[], element_type()[]> is true. [Note 1: The intent is to allow only qualification conversions of the iterator reference type to element_type. — end note]

4

#

Preconditions:

5

#

Hardened preconditions: If extent is not equal to dynamic_extent, then count == extent is true.

6

#

Effects: Initializes data_ with to_address(first) andsize_ with count.

7

#

Throws: Nothing.

🔗

template<class It, class End> constexpr explicit(extent != dynamic_extent) span(It first, End last);

8

#

Constraints: Let U be remove_reference_t<iter_reference_t>.

9

#

Preconditions:

10

#

Hardened preconditions: If extent is not equal to dynamic_extent, then (last - first) == extent is true.

11

#

Effects: Initializes data_ with to_address(first) andsize_ with last - first.

12

#

Throws: When and what last - first throws.

🔗

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

#

Constraints: Let U be remove_pointer_t<decltype(std::data(arr))>.

extent == dynamic_extent || N == extent is true, and

is_convertible_v<U()[], element_type()[]> is true. [Note 3: The intent is to allow only qualification conversions of the array element type to element_type. — end note]

14

#

Effects: Constructs a span that is a view over the supplied array.

[Note 4:

type_identity_t affects class template argument deduction.

— end note]

15

#

Postconditions: size() == N && data() == std::data(arr) is true.

🔗

template<class R> constexpr explicit(extent != dynamic_extent) span(R&& r);

16

#

Constraints: Let U be remove_reference_t<ranges::range_reference_t>.

  • (16.1)

    R satisfies ranges::contiguous_range and ranges::sized_range.

  • (16.2)

    Either R satisfies ranges::borrowed_range oris_const_v<element_type> is true.

  • (16.3)

    remove_cvref_t is not a specialization of span.

  • (16.4)

    remove_cvref_t is not a specialization of array.

  • (16.5)

    is_array_v<remove_cvref_t> is false.

  • (16.6)

    is_convertible_v<U()[], element_type()[]> is true. [Note 5: The intent is to allow only qualification conversions of the range reference type to element_type. — end note]

17

#

Preconditions:

18

#

Hardened preconditions: If extent is not equal to dynamic_extent, then ranges::size(r) == extent is true.

19

#

Effects: Initializes data_ with ranges::data(r) andsize_ with ranges::size(r).

20

#

Throws: What and when ranges::data(r) and ranges::size(r) throw.

🔗

constexpr explicit(extent != dynamic_extent) span(std::initializer_list<value_type> il);

21

#

Constraints: is_const_v<element_type> is true.

22

#

Hardened preconditions: If extent is not equal to dynamic_extent, then il.size() == extent is true.

23

#

Effects: Initializes data_ with il.begin() andsize_ with il.size().

🔗

constexpr span(const span& other) noexcept = default;

24

#

Postconditions: other.size() == size() && other.data() == data().

🔗

template<class OtherElementType, size_t OtherExtent> constexpr explicit(see below) span(const span<OtherElementType, OtherExtent>& s) noexcept;

25

#

Constraints:

extent == dynamic_extent || OtherExtent == dynamic_extent || extent == OtherExtent is true, and

is_convertible_v<OtherElementType()[], element_type()[]> is true. [Note 6: The intent is to allow only qualification conversions of the OtherElementType to element_type. — end note]

26

#

Hardened preconditions: If extent is not equal to dynamic_extent, then s.size() == extent is true.

27

#

Effects: Constructs a span that is a view over the range [s.data(), s.data() + s.size()).

28

#

Postconditions: size() == s.size() && data() == s.data().

29

#

Remarks: The expression inside explicit is equivalent to:extent != dynamic_extent && OtherExtent == dynamic_extent

🔗

constexpr span& operator=(const span& other) noexcept = default;

30

#

Postconditions: size() == other.size() && data() == other.data().