Header c_str_view.h

template<typename Char>
class basic_c_str_view

A string view type for null-terminated strings.

Template Parameters

Char – The character type

Public Functions

inline constexpr const_reference front() const noexcept

Get the first character.

inline constexpr const Char *data() const noexcept

Get a pointer to the C-string.

inline constexpr const Char *c_str() const noexcept

Get a pointer to the C-string.

inline constexpr size_t size() const noexcept

Get the length of the string, excluding the null terminator

Remark

This function is not \(O(1)\). It calls strlen.

inline constexpr size_t length() const noexcept

Same as size()

inline constexpr bool empty() const noexcept

Check if the view is empty.

inline constexpr void remove_prefix(const size_t n) noexcept

Remove prefix with a certain length from the view.

inline constexpr void swap(basic_c_str_view &other) noexcept

Swap two views.

inline explicit constexpr operator std::basic_string_view<Char>() const noexcept

Convert this null-terminated view into a regular std::basic_string_view<Char>.

Friends

inline friend constexpr friend void swap (basic_c_str_view &lhs, basic_c_str_view &rhs) noexcept

Swap two views.

struct sentinel

Sentinel type.

Public Functions

inline constexpr bool operator==(const Char *ptr) const

Comparison with character pointer, compares equal when the character is null.