[string.access] (original) (raw)

21 Strings library [strings]

21.3 String classes [string.classes]

21.3.2 Class template basic_­string [basic.string]

21.3.2.5 Element access [string.access]

constexpr const_reference operator[](size_type pos) const;constexpr reference operator[](size_type pos);

Preconditions: pos <= size().

Returns: *(begin() + pos) if pos < size().

Otherwise, returns a reference to an object of type charT with valuecharT(), where modifying the object to any value other thancharT() leads to undefined behavior.

Complexity:Constant time.

constexpr const_reference at(size_type pos) const;constexpr reference at(size_type pos);

Throws: out_­of_­rangeifpos >= size().

Returns: operator[](pos).

constexpr const charT& front() const;constexpr charT& front();

Effects:Equivalent to: return operator[](0);

constexpr const charT& back() const;constexpr charT& back();

Effects:Equivalent to: return operator[](size() - 1);