Skip to main content

fixstr::basic_fixed_string::data

1#
[[nodiscard]] constexpr pointer data() noexcept;
2#
[[nodiscard]] constexpr const_pointer data() const noexcept;

Returns a pointer to the underlying array serving as character storage.

The pointer is such that the range [data(); data() + size()] is valid and the values in it correspond to the values stored in the string.

The returned array is null-terminated, that is, data() and c_str() perform the same function.

Parameters#

(none)

Return value#

A pointer to the underlying character storage. data() + i == std::addressof(operator[](i)) for every i in [0, size()].

Complexity#

Constant.

Example#

#include <fixed_string.hpp>#include <iostream>#include <memory>
int main(){    {        fixstr::fixed_string hw_s = "hello, world!";        char* const f = std::addressof(hw_s.front());        *f = 'H';        std::cout << "data() after modification: " << hw_s.data() << '\n'; // Hello, world!    }
    {        constexpr const fixstr::fixed_string hw_c = "Hello, world!";        const char* const f = std::addressof(hw_c.front());        std::cout << std::boolalpha << "f == data(): " << (f == hw_c.data()) << '\n';     }}
Output:
data() after modification: Hello, world!f == data(): true