![]() |
Arene Base
Fundamental Utilities For Safety Critical C++
|
A read-only string-view that provides a view onto a null-terminated string. More...

Public Types | |
| using | const_iterator = ::arene::base::detail::wrapped_iterator<const_pointer, passkey> |
| The type of const iterator used by this view. | |
| using | const_pointer = value_type const* |
| The const pointer type of this view. | |
| using | const_reference = value_type const& |
| The type of a reference to an element in the view. | |
| using | difference_type = typename iterator::difference_type |
| The type used for differences between iterators in this view. | |
| using | iterator = const_iterator |
| The type of iterator used by this view. | |
| using | pointer = value_type* |
| The pointer type of this view. | |
| using | reference = value_type& |
| The type of a reference to an element in the view. | |
| using | size_type = std::size_t |
| The type used for sizes in this view. | |
| using | value_type = detail::character |
| The value type of this view. | |
Public Member Functions | |
| constexpr | null_terminated_string_view () noexcept |
| construct an empty string-view. | |
| constexpr | null_terminated_string_view (detail::raw_c_string const string) noexcept |
| construct a view on an existing null-terminated string. | |
| constexpr | null_terminated_string_view (null_terminated_string_view &&)=default |
| default move constructor | |
| constexpr | null_terminated_string_view (null_terminated_string_view const &)=default |
| default copy constructor | |
| null_terminated_string_view (std::nullptr_t)=delete | |
| constructing from a nullptr literal is always an error. | |
| template<typename String, constraints< std::enable_if_t< std::is_same< String, std::string >::value > > = nullptr> | |
| null_terminated_string_view (String const &string) noexcept | |
| Implicit construction from a std::string (which is required to be null-terminated). | |
| ~null_terminated_string_view ()=default | |
| default destructor | |
| ARENE_NODISCARD constexpr auto | begin () const noexcept -> const_iterator |
| Get an iterator to the first element of the string. | |
| ARENE_NODISCARD constexpr auto | c_str () const noexcept -> const_pointer |
| Obtain a C-style null-terminated string pointer. | |
| constexpr auto | compare (null_terminated_string_view const other) const noexcept -> integral_comparison_result |
| Compare this null-terminated string to another null-terminated string. | |
| template<typename String, constraints< std::enable_if_t< std::is_same< String, std::string >::value > > = nullptr> | |
| auto | compare (String const &other) const noexcept -> integral_comparison_result |
| Compare this null-terminated string to a std::string. | |
| constexpr auto | compare (string_view const &other) const noexcept -> integral_comparison_result |
| Compare this null-terminated string to a string_view. | |
| ARENE_NODISCARD constexpr auto | data () const noexcept -> const_pointer |
| Obtain a C-style null-terminated string pointer. | |
| ARENE_NODISCARD constexpr auto | empty () const noexcept -> bool |
| Query if this string is the empty string. | |
| ARENE_NODISCARD constexpr auto | length () const noexcept -> size_type |
| Query the length of the string. | |
| constexpr | operator string_view () const noexcept |
| Implicit conversion to string_view. | |
| constexpr auto | operator= (null_terminated_string_view &&) -> null_terminated_string_view &=default |
| default move assignment | |
| constexpr auto | operator= (null_terminated_string_view const &) -> null_terminated_string_view &=default |
| default copy assignment | |
| ARENE_NODISCARD constexpr auto | size () const noexcept -> size_type |
| Query the length of the string. | |
| ARENE_NODISCARD constexpr auto | substr (std::size_t offset) const noexcept -> null_terminated_string_view |
| Compute the sub-string starting at the specified offset within the string. | |
| ARENE_NODISCARD constexpr auto | substr (std::size_t offset, std::size_t max_length) const noexcept -> string_view |
| Compute the sub-string starting at the specified offset and with the specified maximum length. | |
Static Public Member Functions | |
| static ARENE_NODISCARD constexpr auto | end () noexcept -> sentinel |
| Get the sentinel (end-iterator) of this string. | |
| static constexpr auto | three_way_compare (null_terminated_string_view const lhs, detail::raw_c_string const rhs) noexcept -> strong_ordering |
| Compare two null-terminated strings. | |
| static constexpr auto | three_way_compare (null_terminated_string_view const lhs, null_terminated_string_view const rhs) noexcept -> strong_ordering |
| Compare two null-terminated strings. | |
| template<typename String, constraints< std::enable_if_t< std::is_same< String, std::string >::value > > = nullptr> | |
| static auto | three_way_compare (null_terminated_string_view const lhs, String const &rhs) noexcept -> strong_ordering |
Compare a null-terminated string to a std::string. | |
| static constexpr auto | three_way_compare (null_terminated_string_view const lhs, string_view const rhs) noexcept -> strong_ordering |
Compare a null-terminated string to a string_view. | |
Friends | |
| ARENE_NODISCARD friend constexpr auto | operator!= (iterator const iter, sentinel) noexcept -> bool |
| Equality comparison for a null terminated string view's iterator and the end-of-string sentinel. | |
| ARENE_NODISCARD friend constexpr auto | operator== (iterator const iter, sentinel) noexcept -> bool |
| Equality comparison for a null terminated string view's iterator and the end-of-string sentinel. | |
A read-only string-view that provides a view onto a null-terminated string.
This string type can be used to pass around null-terminated strings more safely and explicitly compared to passing a 'const char*', making it easier to query the length of the string, compare strings, compute sub-strings, etc.
This class just holds a reference to a string stored elsewhere. The null_terminated_string_view does not own the elements of the string.
You should prefer to use string_view over this class unless the extra storage of the size_t required by string_view is prohibitively expensive compared to the cost of repeatedly calculating the string length every time it is used.
| using arene::base::null_terminated_string_view::const_iterator = ::arene::base::detail::wrapped_iterator<const_pointer, passkey> |
The type of const iterator used by this view.
The const pointer type of this view.
The type of a reference to an element in the view.
| using arene::base::null_terminated_string_view::difference_type = typename iterator::difference_type |
The type used for differences between iterators in this view.
The type of iterator used by this view.
The pointer type of this view.
The type of a reference to an element in the view.
The type used for sizes in this view.
| using arene::base::null_terminated_string_view::value_type = detail::character |
The value type of this view.
|
inlineconstexprnoexcept |
construct an empty string-view.
|
constexprdefault |
default copy constructor
|
constexprdefault |
default move constructor
|
default |
default destructor
|
explicitdelete |
constructing from a nullptr literal is always an error.
|
inlineexplicitconstexprnoexcept |
construct a view on an existing null-terminated string.
| string | A pointer to the first character of the null-terminated string. Caller must ensure that the string is properly null-terminated. Passing a nullptr has undefined behaviour. |
|
inlinenoexcept |
Implicit construction from a std::string (which is required to be null-terminated).
The resulting string view is invalidated by any operation that modifies the string.
| string | The source string |
const std::string& to avoid the possibility of unknowingly constructing a temporary std::string implicitly by passing something that is convertible to std::string. e.g. a std::initializer_list<char>
|
inlineconstexprnoexcept |
Get an iterator to the first element of the string.
|
inlineconstexprnoexcept |
Obtain a C-style null-terminated string pointer.
|
inlineconstexprnoexcept |
Compare this null-terminated string to another null-terminated string.
| other | The other string to compare *this to. |
*this lexicographically precedes other, a positive value if other lexicographically precedes *this, or zero if the two strings are equal.
|
inlinenoexcept |
Compare this null-terminated string to a std::string.
| other | The other string to compare *this to. |
*this lexicographically precedes other, a positive value if other lexicographically precedes *this, or zero if the two strings are equal.const std::string& to handle when std::string is only declared, not defined.
|
inlineconstexprnoexcept |
Compare this null-terminated string to a string_view.
| other | The other string to compare *this to. |
*this lexicographically precedes other, a positive value if other lexicographically precedes *this, or zero if the two strings are equal.
|
inlineconstexprnoexcept |
Obtain a C-style null-terminated string pointer.
|
inlineconstexprnoexcept |
Query if this string is the empty string.
|
inlinestaticconstexprnoexcept |
Get the sentinel (end-iterator) of this string.
|
inlineconstexprnoexcept |
Query the length of the string.
length() repeatedly then either cache the value or convert this object to a string_view first and use that instead.
|
inlineconstexprnoexcept |
Implicit conversion to string_view.
|
constexprdefault |
default move assignment
|
constexprdefault |
default copy assignment
|
inlineconstexprnoexcept |
Query the length of the string.
size() repeatedly then either cache the value or convert this object to a string_view first and use that instead.
|
inlineconstexprnoexcept |
Compute the sub-string starting at the specified offset within the string.
| offset | The index of the first character that the returned substring should start at. |
offset and continues to the end of the string. If offset is larger than length() then returns the empty string view.
|
inlineconstexprnoexcept |
Compute the sub-string starting at the specified offset and with the specified maximum length.
| offset | The index of the first charcter of the substring. If this value is greater than length() then returns the empty sub-string. |
| max_length | The maximum length of the returned substring. The returned substring may be shorter than this length if there are fewer than max_length elements after offset. |
offset with a length at most max_length.
|
inlinestaticconstexprnoexcept |
Compare two null-terminated strings.
| lhs | The first string to compare |
| rhs | The second string to compare |
lhs lexicographically precedes rhs rhs lexicographically precedes lhs
|
inlinestaticconstexprnoexcept |
Compare two null-terminated strings.
| lhs | The first string to compare |
| rhs | The second string to compare |
lhs lexicographically precedes rhs rhs lexicographically precedes lhs
|
inlinestaticnoexcept |
Compare a null-terminated string to a std::string.
| lhs | The first string to compare |
| rhs | The second string to compare |
lhs lexicographically precedes rhs rhs lexicographically precedes lhs const std::string& to handle when std::string is only declared, not defined.
|
inlinestaticconstexprnoexcept |
Compare a null-terminated string to a string_view.
| lhs | The first string to compare |
| rhs | The second string to compare |
lhs lexicographically precedes rhs rhs lexicographically precedes lhs
|
friend |
Equality comparison for a null terminated string view's iterator and the end-of-string sentinel.
| iter | The iterator to compare against the sentinel. |
'\0' character.
|
friend |
Equality comparison for a null terminated string view's iterator and the end-of-string sentinel.
| iter | The iterator to compare against the sentinel. |
'\0' character.