Example

Complexity

Constant.

Iterator validity

No changes.

Data races

The container is accessed (neither the const nor the non-const versions modify the container).
The reference returned can be used to access or modify characters. Concurrently accessing or modifying different characters is safe.

Exception safety

If the basic_string is not empty, the function never throws exceptions (no-throw guarantee).
Otherwise, it causes undefined behavior.