21 Strings library [strings]

21.4 String view classes [string.view]

21.4.3 Class template basic_­string_­view [string.view.template]

21.4.3.2 Construction and assignment [string.view.cons]

constexpr basic_string_view() noexcept;
Postconditions: size_­ == 0 and data_­ == nullptr.
constexpr basic_string_view(const charT* str);
Preconditions: [str, str + traits​::​length(str)) is a valid range.
Effects: Constructs a basic_­string_­view, initializing data_­ with str and initializing size_­ with traits​::​length(str).
Complexity: .
constexpr basic_string_view(const charT* str, size_type len);
Preconditions: [str, str + len) is a valid range.
Effects: Constructs a basic_­string_­view, initializing data_­ with str and initializing size_­ with len.
template<class It, class End> constexpr basic_string_view(It begin, End end);
Constraints:
Preconditions:
Effects: Initializes data_­ with to_­address(begin) and initializes size_­ with end - begin.
Throws: When and what end - begin throws.
template<class R> constexpr basic_string_view(R&& r);
Let d be an lvalue of type remove_­cvref_­t<R>.
Constraints:
  • remove_­cvref_­t<R> is not the same type as basic_­string_­view,
  • R models ranges​::​contiguous_­range and ranges​::​sized_­range,
  • is_­same_­v<ranges​::​range_­value_­t<R>, charT> is true,
  • is_­convertible_­v<R, const charT*> is false,
  • d.operator ​::​std​::​basic_­string_­view<charT, traits>() is not a valid expression, and
  • if the qualified-id remove_­reference_­t<R>​::​traits_­type is valid and denotes a type, is_­same_­v<remove_­reference_­t<R>​::​traits_­type, traits> is true.
Effects: Initializes data_­ with ranges​::​data(r) and size_­ with ranges​::​size(r).
Throws: Any exception thrown by ranges​::​data(r) and ranges​::​size(r).