Skip to main content

fixstr::basic_fixed_string::operator[]

1#
[[nodiscard]] constexpr reference operator[](size_type pos);
2#
[[nodiscard]] constexpr const_reference operator[](size_type pos) const;

Returns a reference to the character at specified location pos. No bounds checking is performed. If pos > size(), the behavior is undefined.

If pos == size(), a reference to the character with value TChar() (the null character) is returned.

For the first (non-const) version, the behavior is undefined if this character is modified to any value other than TChar().

Parameters#

  • pos - position of the element to return

Return value#

Reference to the requested element.

Complexity#

Constant.

Example#

#include <cctype>#include <fixed_string.hpp>#include <iostream>
int main(){    fixstr::fixed_string str = "Hello, World!";    std::cout << str << std::endl;
    str[0] = std::tolower(str[0]);    str[7] = std::tolower(str[7]);
    std::cout << str << std::endl;
    // [[maybe_unused]] const auto foo = str[25]; // Undefined behaviour: the index is out of range}
Output:
Hello, World!hello, world!