[string.view.access] (original) (raw)

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.5 Element access [string.view.access]

constexpr const_reference operator[](size_type pos) const;

Preconditions: pos < size().

[Note 1:

Unlike basic_­string​::​operator[],basic_­string_­view​::​operator[](size()) has undefined behavior instead of returning charT().

— _end note_]

constexpr const_reference at(size_type pos) const;

Throws: out_­of_­range if pos >= size().

constexpr const_reference front() const;

constexpr const_reference back() const;

Returns: data_­[size() - 1].

constexpr const_pointer data() const noexcept;

[Note 2:

Unlike basic_­string​::​data() and string-literals,data() can return a pointer to a buffer that is not null-terminated.

Therefore it is typically a mistake to pass data() to a function that takes just a const charT* and expects a null-terminated string.

— _end note_]