Skip to main content

fixstr::basic_fixed_string::at

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

Returns a reference to the element at specified location pos, with bounds checking.

If pos is not within the range of the container, an exception of type std::out_of_range is thrown.

Parameters#

  • pos - position of the element to return

Return value#

Reference to the requested element.

Exceptions#

std::out_of_range if pos > size().

Complexity#

Constant.

Example#

#include <fixed_string.hpp>#include <iostream>
int main(){    fixstr::fixed_string str = "Hello, World!";    try    {        std::cout << str.at(0) << std::endl;        std::cout << str.at(25) << std::endl;    }    catch (std::exception& error)    {        std::cout << error.what() << std::endl;    }}

Possible output:

Harray::at
note

In the implementation the call to at member function is delegated to std::array that serves as an underlying storage. That's why error.what() returns array::at.