Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
null_terminated_string_view.hpp
Go to the documentation of this file.
1// Copyright 2024, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_STRINGS_NULL_TERMINATED_STRING_VIEW_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_STRINGS_NULL_TERMINATED_STRING_VIEW_HPP_
7
8// IWYU pragma: private
9// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
10
11// parasoft-begin-suppress AUTOSAR-A7_1_5-a-2 "Trailing return syntax permitted by A7-1-5 Permit #1 v1.0.0"
12
13// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
19#include "arene/base/detail/raw_c_string.hpp"
20#include "arene/base/detail/wrapped_iterator.hpp" // IWYU pragma: keep
24#include "arene/base/stdlib_choice/cstddef.hpp"
25#include "arene/base/stdlib_choice/enable_if.hpp"
26#include "arene/base/stdlib_choice/integral_constant.hpp"
27#include "arene/base/stdlib_choice/is_same.hpp"
28#include "arene/base/stdlib_choice/string.hpp"
29#include "arene/base/strings/detail/lexicographic_string_compare.hpp"
30#include "arene/base/strings/detail/string_length.hpp"
31#include "arene/base/strings/detail/string_view_ostream_mixin.hpp" // IWYU pragma: keep
33// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
34
35// parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
36// parasoft-begin-suppress AUTOSAR-M2_10_1-a-2 "Similar names permitted by M2-10-1 Permit #1"
37
38namespace arene {
39namespace base {
40
41// Exception: AUTOSAR Rule M5-0-15 (required, implementation, automated)
42// Array indexing shall be the only form of pointer arithmetic.
43//
44// The purpose of this class is to abstract out the use of pointer arithmetic necessary to process null-terminated
45// strings and string literals. Pointer arithmetic is only used to adjust the pointer within the array containing the
46// string up until the null-terminator, as covered by M5-0-16 and M5-0-17, unless iterators are incremented unchecked.
47
48// parasoft-begin-suppress AUTOSAR-A12_1_5-a-2 "False positive: delegating constructors are used"
49/// @brief A read-only string-view that provides a view onto a null-terminated string.
50///
51/// This string type can be used to pass around null-terminated strings more safely and explicitly compared to passing
52/// a 'const char*', making it easier to query the length of the string, compare strings, compute sub-strings, etc.
53///
54/// This class just holds a reference to a string stored elsewhere. The null_terminated_string_view does not own the
55/// elements of the string.
56///
57/// You should prefer to use string_view over this class unless the extra storage of the size_t required by
58/// string_view is prohibitively expensive compared to the cost of repeatedly calculating the string length
59/// every time it is used.
61 : generic_ordering_from_three_way_compare<null_terminated_string_view>
62 , string_view_ostream_mixin<null_terminated_string_view> {
63 /// @brief simple tag passkey type to protect iterator construction.
64 class passkey {
65 public:
66 /// @brief explicit private ctor to prevent construction from {}
67 constexpr explicit passkey() = default;
68 };
69
70 /// @brief Internal type alias for the base class
72
73 // parasoft-begin-suppress AUTOSAR-A3_9_1-b-2 "Returning an int for compatibility with std::string_view"
74 /// @brief The type of comparisons that yield an integer rather than a @c strong_ordering
75 using integral_comparison_result = int;
76 // parasoft-end-suppress AUTOSAR-A3_9_1-b-2
77
78 public:
79 // parasoft-begin-suppress AUTOSAR-A12_1_1-a-2 "False positive: This constructor delegates to another, which does
80 // initialize the base class"
81 /// @brief construct an empty string-view.
84 // parasoft-end-suppress AUTOSAR-A12_1_1-a-2
85
86 /// @brief default copy constructor
88
89 /// @brief default copy assignment
91
92 /// @brief default move constructor
94
95 /// @brief default move assignment
97
98 /// @brief default destructor
100
101 /// @brief constructing from a nullptr literal is always an error.
103
104 // parasoft-begin-suppress AUTOSAR-A7_1_3-a-2 "False Positive: const is on rhs"
105 /// @brief construct a view on an existing null-terminated string.
106 ///
107 /// @param string A pointer to the first character of the null-terminated
108 /// string. Caller must ensure that the string is properly null-terminated.
109 /// Passing a nullptr has undefined behaviour.
110 // NOLINTNEXTLINE(readability-avoid-const-params-in-decls)
111 constexpr explicit null_terminated_string_view(detail::raw_c_string const string) noexcept;
112 // parasoft-end-suppress AUTOSAR-A7_1_3-a-2
113
114 /// @brief Implicit construction from a std::string (which is required to be
115 /// null-terminated).
116 ///
117 /// The resulting string view is invalidated by any operation that modifies
118 /// the string.
119 ///
120 /// @param string The source string
121 ///
122 /// @note This constructor is a template rather than a non-template taking a
123 /// <c>const std::string&</c> to avoid the possibility of unknowingly
124 /// constructing a temporary @c std::string implicitly by passing something
125 /// that is convertible to @c std::string.
126 /// e.g. a @c std::initializer_list<char>
127 template <typename String, constraints<std::enable_if_t<std::is_same<String, std::string>::value>> = nullptr>
128 // NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions)
129 null_terminated_string_view(String const& string) noexcept
130 : compare_base{},
131 string_(string.c_str()) {}
132
133 /// @brief This type represents the sentinel of the range of characters.
134 ///
135 /// The return-type of @c end() method.
136 class sentinel {};
137
138 /// @brief The value type of this view
139 using value_type = detail::character;
140 /// @brief The pointer type of this view
142 /// @brief The const pointer type of this view
143 using const_pointer = value_type const*;
144 /// @brief The type of a reference to an element in the view
146 /// @brief The type of a reference to an element in the view
148 /// @brief The type of const iterator used by this view.
149 using const_iterator = ::arene::base::detail::wrapped_iterator<const_pointer, passkey>;
150 /// @brief The type of iterator used by this view.
152 /// @brief The type used for sizes in this view
154 /// @brief The type used for differences between iterators in this view
155 using difference_type = typename iterator::difference_type;
156
157 // parasoft-begin-suppress AUTOSAR-A13_5_5-b-2 "Comparison of iterator with sentinel"
158 // parasoft-begin-suppress AUTOSAR-A11_3_1-a-2 "False positive: comparison operators are permitted"
159 /// @brief Equality comparison for a null terminated string view's iterator and the end-of-string sentinel.
160 ///
161 /// @param iter The iterator to compare against the sentinel.
162 /// @return true if the iterator points to a @c '\0' character.
163 /// @return false Otherwise.
164 ARENE_NODISCARD friend constexpr auto operator==(iterator const iter, sentinel) noexcept -> bool {
165 return *iter.base() == '\0';
166 }
167 // parasoft-end-suppress AUTOSAR-A11_3_1-a-2
168 // parasoft-end-suppress AUTOSAR-A13_5_5-b-2
169
170 // parasoft-begin-suppress AUTOSAR-A13_5_5-b-2 "Comparison of iterator with sentinel"
171 // parasoft-begin-suppress AUTOSAR-A11_3_1-a-2 "False positive: comparison operators are permitted"
172 /// @brief Equality comparison for a null terminated string view's iterator and the end-of-string sentinel.
173 ///
174 /// @param iter The iterator to compare against the sentinel.
175 /// @return true if the iterator points to a @c '\0' character.
176 /// @return false Otherwise.
177 ARENE_NODISCARD friend constexpr auto operator!=(iterator const iter, sentinel) noexcept -> bool {
178 return !(iter == null_terminated_string_view::sentinel{});
179 }
180 // parasoft-end-suppress AUTOSAR-A11_3_1-a-2
181 // parasoft-end-suppress AUTOSAR-A13_5_5-b-2
182
183 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: identifier 'begin' does not hide anything"
184 /// @brief Get an iterator to the first element of the string.
185 /// @return const_iterator An iterator to the first character in the string.
186 ARENE_NODISCARD constexpr auto begin() const noexcept -> const_iterator { return const_iterator{passkey{}, string_}; }
187 // parasoft-end-suppress AUTOSAR-A2_10_1-d
188
189 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: identifier 'end' does not hide anything"
190 /// @brief Get the sentinel (end-iterator) of this string.
191 /// @return sentinel The sentinel comparable to an iterator to mark the end of the string.
192 // If we make this a static method then we end up getting warnings at the usage site about calling a static member
193 // function using .end() syntax. So instead we rather keep this as a non-static member function.
194 // NOLINTNEXTLINE(readability-convert-member-functions-to-static)
195 ARENE_NODISCARD static constexpr auto end() noexcept -> sentinel { return {}; }
196 // parasoft-end-suppress AUTOSAR-A2_10_1-d
197
198 /// @brief Query if this string is the empty string.
199 /// @return true if the string is empty, false otherwise
200 ARENE_NODISCARD constexpr auto empty() const noexcept -> bool { return begin() == end(); }
201
202 /// @brief Query the length of the string.
203 ///
204 /// @return The number of 'char' elements in the null-terminate string, not including the null-terminator.
205 ///
206 /// @note This operation needs to traverse the string to determine the length and so may be expensive to call
207 /// repeatedly. If you need to call @c length() repeatedly then either cache the value or convert this object to a
208 /// @c string_view first and use that instead.
209 ARENE_NODISCARD constexpr auto length() const noexcept -> size_type { return detail::string_length(string_); }
210
211 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: 'size' does not hide anything"
212 /// @brief Query the length of the string.
213 ///
214 /// @return The number of 'char' elements in the null-terminate string, not including the null-terminator.
215 ///
216 /// @note This operation needs to traverse the string to determine the length and so may be expensive to call
217 /// repeatedly. If you need to call @c size() repeatedly then either cache the value or convert this object to a @c
218 /// string_view first and use that instead.
219 ARENE_NODISCARD constexpr auto size() const noexcept -> size_type { return length(); }
220 // parasoft-end-suppress AUTOSAR-A2_10_1-d
221
222 /// @brief Obtain a C-style null-terminated string pointer.
223 /// @return const_pointer A pointer to the first character in the string.
224 ARENE_NODISCARD constexpr auto c_str() const noexcept -> const_pointer { return string_; }
225
226 /// @brief Obtain a C-style null-terminated string pointer.
227 /// @return const_pointer A pointer to the first character in the string.
228 ARENE_NODISCARD constexpr auto data() const noexcept -> const_pointer { return string_; }
229
230 // parasoft-begin-suppress AUTOSAR-A13_5_2-a-2 "Implicit conversion to string_view is part of the API"
231 /// @brief Implicit conversion to string_view.
232 ///
233 /// @return A string_view that spans the characters of *this, minus the null-terminator.
234 // NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions)
235 constexpr operator string_view() const noexcept { return {data(), length()}; }
236 // parasoft-end-suppress AUTOSAR-A13_5_2-a-2
237
238 /// @brief Compute the sub-string starting at the specified offset within the string.
239 ///
240 /// @param offset The index of the first character that the returned substring should start at.
241 ///
242 /// @return null_terminated_string_view A view which starts at the character at index @c offset and continues to
243 /// the end of the string. If @c offset is larger than @c length() then returns the empty string view.
244 ///
245 /// @note This operation has complexity of O(min(offset, length())).
246 // parasoft-begin-suppress AUTOSAR-A15_4_5-a "False positive: There is no function that throws an excpetion of 'Any'
247 // type"
248 ARENE_NODISCARD constexpr auto substr(std::size_t offset) const noexcept -> null_terminated_string_view;
249 // parasoft-end-suppress AUTOSAR-A15_4_5-a
250
251 /// @brief Compute the sub-string starting at the specified offset and with the specified maximum length.
252 ///
253 /// @param offset The index of the first charcter of the substring. If this value is greater than @c length() then
254 /// returns the empty sub-string.
255 /// @param max_length The maximum length of the returned substring. The returned substring may be shorter than this
256 /// length if there are fewer than @c max_length elements after @c offset.
257 ///
258 /// @return string_view A substring referencing the elements of *this starting at index @c offset with a length at
259 /// most @c max_length.
260 ///
261 /// @note This operation has complexity of O(min(offset+max_length, length()))
262 // NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
263 ARENE_NODISCARD constexpr auto substr(std::size_t offset, std::size_t max_length) const noexcept -> string_view;
264
265 /// @brief Compare this null-terminated string to another null-terminated string.
266 ///
267 /// @param other The other string to compare *this to.
268 ///
269 /// @return integral_comparison_result A negative value if @c *this lexicographically precedes @c other, a positive
270 /// value if @c other lexicographically precedes @c *this, or zero if the two strings are equal.
271 // parasoft-begin-suppress AUTOSAR-A7_1_3-a-2 "False Positive: const is on rhs"
272 constexpr auto compare(null_terminated_string_view const other) const noexcept -> integral_comparison_result {
273 return from_strong_ordering(three_way_compare(*this, other));
274 }
275 // parasoft-end-suppress AUTOSAR-A7_1_3-a-2
276
277 /// @brief Compare this null-terminated string to a string_view.
278 ///
279 /// @param other The other string to compare *this to.
280 ///
281 /// @return A negative value if @c *this lexicographically precedes @c other, a positive value if @c other
282 /// lexicographically precedes @c *this, or zero if the two strings are equal.
283 constexpr auto compare(string_view const& other) const noexcept -> integral_comparison_result {
284 return from_strong_ordering(three_way_compare(*this, other));
285 }
286
287 /// @brief Compare this null-terminated string to a std::string.
288 ///
289 /// @param other The other string to compare *this to.
290 ///
291 /// @return A negative value if @c *this lexicographically precedes @c other, a positive value if @c other
292 /// lexicographically precedes @c *this, or zero if the two strings are equal.
293 ///
294 /// @note This constructor is a template rather than a non-template taking a <c>const std::string&</c> to handle when
295 /// @c std::string is only declared, not defined.
296 template <typename String, constraints<std::enable_if_t<std::is_same<String, std::string>::value>> = nullptr>
297 auto compare(String const& other) const noexcept -> integral_comparison_result {
298 return compare(string_view(other));
299 }
300
301 /// @brief Compare two null-terminated strings
302 ///
303 /// @param lhs The first string to compare
304 /// @param rhs The second string to compare
305 ///
306 /// @return strong_ordering::less if @c lhs lexicographically precedes @c rhs
307 /// @return strong_ordering::greater if @c rhs lexicographically precedes @c lhs
308 /// @return strong_ordering::equal if the two strings are equal.
309 static constexpr auto three_way_compare(
312 ) noexcept -> strong_ordering {
313 return detail::lexicographic_string_compare(lhs.c_str(), rhs.c_str());
314 }
315
316 /// @brief Compare two null-terminated strings
317 ///
318 /// @param lhs The first string to compare
319 /// @param rhs The second string to compare
320 ///
321 /// @return strong_ordering::less if @c lhs lexicographically precedes @c rhs
322 /// @return strong_ordering::greater if @c rhs lexicographically precedes @c lhs
323 /// @return strong_ordering::equal if the two strings are equal.
324 static constexpr auto
325 three_way_compare(null_terminated_string_view const lhs, detail::raw_c_string const rhs) noexcept -> strong_ordering {
327 }
328
329 /// @brief Compare a null-terminated string to a @c std::string
330 ///
331 /// @param lhs The first string to compare
332 /// @param rhs The second string to compare
333 ///
334 /// @return strong_ordering::less if @c lhs lexicographically precedes @c rhs
335 /// @return strong_ordering::greater if @c rhs lexicographically precedes @c lhs
336 /// @return strong_ordering::equal if the two strings are equal.
337 ///
338 /// @note This constructor is a template rather than a non-template taking a <c>const std::string&</c> to handle when
339 /// @c std::string is only declared, not defined.
340 template <typename String, constraints<std::enable_if_t<std::is_same<String, std::string>::value>> = nullptr>
341 static auto three_way_compare(null_terminated_string_view const lhs, String const& rhs) noexcept -> strong_ordering {
342 return three_way_compare(lhs, string_view{rhs});
343 }
344
345 /// @brief Compare a null-terminated string to a @c string_view
346 ///
347 /// @param lhs The first string to compare
348 /// @param rhs The second string to compare
349 ///
350 /// @return strong_ordering::less if @c lhs lexicographically precedes @c rhs
351 /// @return strong_ordering::greater if @c rhs lexicographically precedes @c lhs
352 /// @return strong_ordering::equal if the two strings are equal.
353 static constexpr auto three_way_compare(null_terminated_string_view const lhs, string_view const rhs) noexcept
354 -> strong_ordering {
355 return opposite_ordering(detail::lexicographic_string_compare({rhs.data(), rhs.size()}, lhs.c_str()));
356 }
357
358 private:
359 /// @brief The pointer to the NUL-terminated string
360 detail::raw_c_string string_;
361};
362// parasoft-end-suppress AUTOSAR-A12_1_5-a-2 "False positive: delegating constructors are used"
363
364/// @brief Compute the sub-string starting at the specified offset within the string.
365///
366/// @param offset The index of the first character that the returned substring should start at.
367///
368/// @return null_terminated_string_view A view which starts at the character at index @c offset and continues to
369/// the end of the string. If @c offset is larger than @c length() then returns the empty string view.
370///
371/// @note This operation has complexity of O(min(offset, length())).
372// parasoft-begin-suppress AUTOSAR-A15_4_5-a "False positive: There is no function that throws an excpetion of 'Any'
373// type"
374ARENE_NODISCARD inline constexpr auto null_terminated_string_view::substr(std::size_t offset) const noexcept
376 detail::raw_c_string start{string_};
377 while ((offset != 0U) && (*start != '\0')) {
378 --offset;
379 arene::base::advance(start, 1);
380 }
381
382 return null_terminated_string_view{start};
383}
384// parasoft-end-suppress AUTOSAR-A15_4_5-a
385
386// parasoft-begin-suppress AUTOSAR-A7_1_3-a-2 "False Positive: const is on rhs"
387/// @brief construct a view on an existing null-terminated string.
388///
389/// @param string A pointer to the first character of the null-terminated
390/// string. Caller must ensure that the string is properly null-terminated.
391/// Passing a nullptr has undefined behaviour.
392inline constexpr null_terminated_string_view::null_terminated_string_view(detail::raw_c_string const string) noexcept
393 : compare_base{},
394 string_(string) {
395 ARENE_PRECONDITION(string != nullptr);
396}
397// parasoft-end-suppress AUTOSAR-A7_1_3-a-2
398
399/// @brief Compute the sub-string starting at the specified offset and with the specified maximum length.
400///
401/// @param offset The index of the first charcter of the substring. If this value is greater than @c length() then
402/// returns the empty sub-string.
403/// @param max_length The maximum length of the returned substring. The returned substring may be shorter than this
404/// length if there are fewer than @c max_length elements after @c offset.
405///
406/// @return string_view A substring referencing the elements of *this starting at index @c offset with a length at
407/// most @c max_length.
408///
409/// @note This operation has complexity of O(min(offset+max_length, length()))
410// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
412 const noexcept -> string_view {
413 auto first = begin();
414 while ((offset != 0U) && (first != end())) {
415 ++first;
416 --offset;
417 }
418
419 auto last = first;
420 while ((max_length != 0U) && (last != end())) {
421 ++last;
422 --max_length;
423 }
424
425 return {first.base(), static_cast<std::size_t>(last - first)};
426}
427
428namespace literals {
429
430// parasoft-begin-suppress AUTOSAR-A7_1_3-a "False positive: const is placed on the right hand side"
431/// @brief Construct a null-terminated string view from a string literal.
432///
433/// For example:
434/// @code
435/// using namespace literals;
436/// auto sv = "a null terminated string"_ntsv;
437/// @endcode
438///
439/// @param str Pointer to the string literal.
440/// @return The null_terminated_string_view referencing the string literal.
441constexpr auto operator""_ntsv(detail::raw_c_string const str, std::size_t /*size*/) noexcept
443 return null_terminated_string_view{str};
444}
445// parasoft-end-suppress AUTOSAR-A7_1_3-a
446
447} // namespace literals
448
449namespace ranges {
450/// @brief Indicate that @c null_terminated_string_view is a borrowed range
451template <>
453} // namespace ranges
454
455} // namespace base
456} // namespace arene
457
458// parasoft-end-suppress AUTOSAR-M2_10_1-a-2
459
460#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_STRINGS_NULL_TERMINATED_STRING_VIEW_HPP_
Provides a backport of C++17's constexpr std::advance.
This type represents the sentinel of the range of characters.
Definition null_terminated_string_view.hpp:136
A read-only string-view that provides a view onto a null-terminated string.
Definition null_terminated_string_view.hpp:62
~null_terminated_string_view()=default
default destructor
static ARENE_NODISCARD constexpr auto end() noexcept -> sentinel
Get the sentinel (end-iterator) of this string.
Definition null_terminated_string_view.hpp:195
::arene::base::detail::wrapped_iterator< const_pointer, passkey > const_iterator
The type of const iterator used by this view.
Definition null_terminated_string_view.hpp:149
value_type const * const_pointer
The const pointer type of this view.
Definition null_terminated_string_view.hpp:143
value_type * pointer
The pointer type of this view.
Definition null_terminated_string_view.hpp:141
constexpr auto compare(string_view const &other) const noexcept -> integral_comparison_result
Compare this null-terminated string to a string_view.
Definition null_terminated_string_view.hpp:283
null_terminated_string_view(std::nullptr_t)=delete
constructing from a nullptr literal is always an error.
null_terminated_string_view(String const &string) noexcept
Implicit construction from a std::string (which is required to be null-terminated).
Definition null_terminated_string_view.hpp:129
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.
Definition null_terminated_string_view.hpp:353
detail::character value_type
The value type of this view.
Definition null_terminated_string_view.hpp:139
ARENE_NODISCARD constexpr auto size() const noexcept -> size_type
Query the length of the string.
Definition null_terminated_string_view.hpp:219
constexpr auto operator=(null_terminated_string_view const &) -> null_terminated_string_view &=default
default copy assignment
ARENE_NODISCARD constexpr auto data() const noexcept -> const_pointer
Obtain a C-style null-terminated string pointer.
Definition null_terminated_string_view.hpp:228
value_type & reference
The type of a reference to an element in the view.
Definition null_terminated_string_view.hpp:145
const_iterator iterator
The type of iterator used by this view.
Definition null_terminated_string_view.hpp:151
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.
Definition null_terminated_string_view.hpp:177
constexpr auto operator=(null_terminated_string_view &&) -> null_terminated_string_view &=default
default move assignment
ARENE_NODISCARD constexpr auto length() const noexcept -> size_type
Query the length of the string.
Definition null_terminated_string_view.hpp:209
constexpr null_terminated_string_view(null_terminated_string_view &&)=default
default move constructor
typename iterator::difference_type difference_type
The type used for differences between iterators in this view.
Definition null_terminated_string_view.hpp:155
ARENE_NODISCARD constexpr auto c_str() const noexcept -> const_pointer
Obtain a C-style null-terminated string pointer.
Definition null_terminated_string_view.hpp:224
auto compare(String const &other) const noexcept -> integral_comparison_result
Compare this null-terminated string to a std::string.
Definition null_terminated_string_view.hpp:297
value_type const & const_reference
The type of a reference to an element in the view.
Definition null_terminated_string_view.hpp:147
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.
Definition null_terminated_string_view.hpp:374
ARENE_NODISCARD constexpr auto empty() const noexcept -> bool
Query if this string is the empty string.
Definition null_terminated_string_view.hpp:200
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.
Definition null_terminated_string_view.hpp:309
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.
Definition null_terminated_string_view.hpp:325
constexpr null_terminated_string_view() noexcept
construct an empty string-view.
Definition null_terminated_string_view.hpp:82
constexpr auto compare(null_terminated_string_view const other) const noexcept -> integral_comparison_result
Compare this null-terminated string to another null-terminated string.
Definition null_terminated_string_view.hpp:272
ARENE_NODISCARD constexpr auto begin() const noexcept -> const_iterator
Get an iterator to the first element of the string.
Definition null_terminated_string_view.hpp:186
std::size_t size_type
The type used for sizes in this view.
Definition null_terminated_string_view.hpp:153
constexpr null_terminated_string_view(null_terminated_string_view const &)=default
default copy constructor
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.
Definition null_terminated_string_view.hpp:164
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.
Definition null_terminated_string_view.hpp:341
An opt-in trait to indicate that a range type is a borrowed range.
Definition enable_borrowed_range.hpp:31
Backport of the C++17 std::string_view class.
Definition string_view.hpp:54
#define ARENE_PRECONDITION(condition)
Check that a precondition holds, and terminate the application if it does not.
Definition contract.hpp:150
Definition byte.hpp:178
Definition accumulate.hpp:37
strong_ordering_detail::strong_ordering strong_ordering
The enumeration specifying the result of an ordering comparison.
Definition strong_ordering.hpp:147
constexpr auto opposite_ordering(strong_ordering const ordering) noexcept -> strong_ordering
Return the opposite ordering for a strong_ordering three-way-comparison result.
Definition strong_ordering.hpp:209
constexpr auto from_strong_ordering(strong_ordering const ordering) noexcept -> int
Convert a strong_ordering into an integer three-way-comparison result.
Definition strong_ordering.hpp:177
Definition accumulate.hpp:36
typedef nullptr_t
The type of nullptr.
Definition cstddef.hpp:33
::size_t size_t
A type suitable for holding the size of an object.
Definition cstddef.hpp:29
bool_constant< true > true_type
An alias for bool_constant<true>
Definition integral_constant.hpp:76
#define ARENE_NODISCARD
An alias for [[nodiscard]] , or a no-op if the attribute is not supported.
Definition nodiscard.hpp:26