Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
inline_string_reference.hpp
Go to the documentation of this file.
1// Copyright 2026, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_STRINGS_INLINE_STRING_REFERENCE_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_STRINGS_INLINE_STRING_REFERENCE_HPP_
7
8// IWYU pragma: private
9// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
10
11// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
12#include "arene/base/compare/operators.hpp"
13#include "arene/base/compare/strong_ordering.hpp"
14#include "arene/base/compiler_support/attributes.hpp"
15#include "arene/base/constraints/constraints.hpp"
16#include "arene/base/contracts/contract.hpp"
17#include "arene/base/detail/exceptions.hpp"
18#include "arene/base/detail/raw_c_string.hpp"
19#include "arene/base/stdlib_choice/cstddef.hpp"
20#include "arene/base/stdlib_choice/enable_if.hpp"
21#include "arene/base/stdlib_choice/ignore.hpp"
22#include "arene/base/strings/inline_string.hpp"
23#include "arene/base/strings/string_view.hpp"
24// parasoft-end-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
25
26namespace arene {
27namespace base {
28
29// parasoft-begin-suppress AUTOSAR-A7_1_5-a "Trailing return syntax permitted by A7-1-5 Permit #1 v1.0.0"
30// parasoft-begin-suppress AUTOSAR-A13_5_1-a "False positive:" rule specifies
31// that a const overload of 'operator[]' is required if a non-const overload of
32// 'operator[]' is defined. These classes only define const overloads."
33
34// forward declaration
36
37namespace inline_string_reference_detail {
38
39/// @brief function pointers to be used inside const member functions
40struct const_operations {
41 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: does not hide anything."
42 /// @brief The type of the base class
43 using string_base = inline_string_detail::inline_string_base;
44 /// @brief The type of a const pointer to the base class
45 using string_ptr = string_base const*;
46 /// @brief The type of a size at the base class
47 using size_type = string_base::size_type;
48 /// @brief The type of a const iterator at the base class
49 using const_iterator = string_base::const_iterator;
50 // parasoft-end-suppress AUTOSAR-A2_10_1-d "False positive: does not hide anything."
51
52 // parasoft-begin-suppress CERT_C-EXP37-b-3 "False positive: The rule does not mention naming all parameters"
53 /// @brief The function pointer type of the data operation
54 using data_op_type = detail::raw_c_string (*)(string_ptr);
55 /// @brief The function pointer type of the size operation
56 using size_op_type = size_type (*)(string_ptr);
57 /// @brief The function pointer type of the capacity operation
58 using capacity_op_type = size_type (*)(string_ptr);
59 /// @brief The function pointer type of the empty operation
60 using empty_op_type = bool (*)(string_ptr);
61 /// @brief The function pointer type of the element accessor
62 using element_op_type = detail::character const& (*)(string_ptr, size_type);
63 /// @brief The function pointer type of the at operation
64 using at_op_type = detail::character const& (*)(string_ptr, size_type);
65 /// @brief The function pointer type of the front operation
66 using front_op_type = detail::character const& (*)(string_ptr);
67 /// @brief The function pointer type of the back operation
68 using back_op_type = detail::character const& (*)(string_ptr);
69 /// @brief The function pointer type of the begin operation
70 using begin_op_type = const_iterator (*)(string_ptr);
71 /// @brief The function pointer type of the end operation
72 using end_op_type = const_iterator (*)(string_ptr);
73 /// @brief The function pointer type of the to_string_view operation
74 using to_string_view_op_type = string_view (*)(string_ptr);
75 // parasoft-end-suppress CERT_C-EXP37-b-3 "False positive: The rule does not mention naming all parameters"
76
77 /// @brief The function pointer of the data operation
78 data_op_type data;
79 /// @brief The function pointer of the size operation
80 size_op_type size;
81 /// @brief The function pointer of the capacity operation
82 capacity_op_type capacity;
83 /// @brief The function pointer of the empty operation
84 empty_op_type empty;
85 /// @brief The function pointer of the element accessor
86 element_op_type element;
87 /// @brief The function pointer of the at operation
88 at_op_type at;
89 /// @brief The function pointer of the front operation
90 front_op_type front;
91 /// @brief The function pointer of the back operation
92 back_op_type back;
93 /// @brief The function pointer of the begin iterator
94 begin_op_type begin;
95 /// @brief The function pointer of the end iterator
96 end_op_type end;
97 /// @brief The function pointer of the to_string_view operation
98 to_string_view_op_type to_string_view;
99};
100
101/// @brief Implementation of the const operations of a specific MaxSize
102/// @tparam MaxSize The maximum capacity of the string, _not_ including the null terminator
103template <std::size_t MaxSize>
104class const_operations_impl {
105 public:
106 /// @brief The type of the underlying string
107 using this_string = inline_string<MaxSize>;
108
109 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: does not hide anything."
110 /// @brief The type of a pointer to the base class of the underlying string
111 using string_ptr = const_operations::string_ptr;
112 /// @brief The type of a size at the base class
113 using size_type = const_operations::size_type;
114 /// @brief The type of a const iterator at the base class
115 using const_iterator = const_operations::const_iterator;
116 // parasoft-end-suppress AUTOSAR-A2_10_1-d "False positive: does not hide anything."
117
118 /// @brief Cast base class pointer back to the underlying string type
119 /// @param ptr The base class pointer
120 /// @return The pointer as the underlying string type
121 static constexpr auto string(string_ptr ptr) noexcept -> this_string const* {
122 return static_cast<inline_string<MaxSize> const*>(ptr);
123 }
124
125 /// @brief Return a pointer to the NUL-terminated string held in @c *this
126 /// @param ptr The base class pointer
127 /// @return a pointer to the NUL-terminated string held in @c *this
128 static constexpr auto do_data(string_ptr ptr) noexcept -> detail::raw_c_string { return string(ptr)->data(); }
129
130 /// @brief Get the length of the string
131 /// @param ptr The base class pointer
132 /// @return The number of characters in the string, non-inclusive of the null-terminator
133 static constexpr auto do_size(string_ptr ptr) noexcept -> size_type { return string(ptr)->size(); }
134
135 /// @brief The maximum length of the string
136 /// @param ptr The base class pointer
137 /// @return size_type @c MaxSize
138 static constexpr auto do_capacity(string_ptr ptr) noexcept -> size_type { return string(ptr)->capacity(); }
139
140 /// @brief Check if the string is empty
141 /// @param ptr The base class pointer
142 /// @return @c true if the string is empty, @c false otherwise
143 static constexpr auto do_empty(string_ptr ptr) noexcept -> bool { return string(ptr)->empty(); }
144
145 /// @brief Retrieve the @c index -th character in the string
146 /// @param ptr The base class pointer
147 /// @param index The index of the character to retrieve
148 /// @return A reference to that character
149 static constexpr auto do_element(string_ptr ptr, size_type index) noexcept -> detail::character const& {
150 return (*string(ptr))[index];
151 }
152 /// @brief Retrieve the @c index -th character in the string
153 /// @tparam AreExceptionsEnabled Used to disable this overload if exceptions are not enabled.
154 /// @param ptr The base class pointer
155 /// @param index The index of the character to retrieve
156 /// @return A reference to that character
157 template <
158 bool AreExceptionsEnabled = detail::are_exceptions_enabled::value,
159 constraints<std::enable_if_t<AreExceptionsEnabled>> = nullptr>
160 static constexpr auto do_at(string_ptr ptr, size_type index) -> detail::character const& {
161 return string(ptr)->at(index);
162 }
163 /// @brief When exceptions are disabled, invoking this is a precondition violation.
164 /// @tparam AreExceptionsEnabled Used to enable this overload if exceptions are not enabled.
165 /// @return Never returns
166 template <
167 bool AreExceptionsEnabled = detail::are_exceptions_enabled::value,
168 constraints<std::enable_if_t<!AreExceptionsEnabled>> = nullptr>
169 ARENE_NORETURN static auto do_at(string_ptr, std::size_t) -> detail::character const& {
170 ARENE_INVARIANT_UNREACHABLE("do_at() called when exceptions are disabled");
171 }
172
173 /// @brief Get the first character in the string
174 /// @param ptr The base class pointer
175 /// @return A reference to the first character
176 static constexpr auto do_front(string_ptr ptr) noexcept -> detail::character const& { return string(ptr)->front(); }
177 /// @brief Get the last character in the string
178 /// @param ptr The base class pointer
179 /// @return A reference to the last character
180 static constexpr auto do_back(string_ptr ptr) noexcept -> detail::character const& { return string(ptr)->back(); }
181
182 /// @brief Iterator to the first position in the string
183 /// @param ptr The base class pointer
184 /// @return An iterator to the first element if not empty, @c end() otherwise
185 static constexpr auto do_begin(string_ptr ptr) noexcept -> const_iterator { return string(ptr)->begin(); }
186 /// @brief The one-past-the-last position in the string
187 /// @param ptr The base class pointer
188 /// @return An iterator to the one-past-the-last position in the string
189 static constexpr auto do_end(string_ptr ptr) noexcept -> const_iterator { return string(ptr)->end(); }
190
191 /// @brief Convert to string view
192 /// @param ptr The base class pointer
193 /// @return A string_view object referencing the data
194 static constexpr auto do_to_string_view(string_ptr ptr) noexcept -> string_view {
195 return {do_data(ptr), do_size(ptr)};
196 }
197};
198
199/// @brief Instance of a holder of the const operations of a specific size
200/// @tparam MaxSize The maximum capacity of the string, _not_ including the null terminator
201template <std::size_t MaxSize>
202extern constexpr const_operations const_string_operations{
203 &const_operations_impl<MaxSize>::do_data,
204 &const_operations_impl<MaxSize>::do_size,
205 &const_operations_impl<MaxSize>::do_capacity,
206 &const_operations_impl<MaxSize>::do_empty,
207 &const_operations_impl<MaxSize>::do_element,
208 &const_operations_impl<MaxSize>::do_at,
209 &const_operations_impl<MaxSize>::do_front,
210 &const_operations_impl<MaxSize>::do_back,
211 &const_operations_impl<MaxSize>::do_begin,
212 &const_operations_impl<MaxSize>::do_end,
213 &const_operations_impl<MaxSize>::do_to_string_view,
214};
215
216/// @brief function pointers to be used inside member functions
217struct operations {
218 /// @brief The type of the base class
219 using string_base = inline_string_detail::inline_string_base;
220 /// @brief The type of a pointer to the base class
221 using string_ptr = string_base*;
222 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: does not hide anything."
223 /// @brief The type of a size at the base class
224 using size_type = string_base::size_type;
225 /// @brief The type of an iterator at the base class
226 using iterator = string_base::iterator;
227 /// @brief The type of a const iterator at the base class
228 using const_iterator = string_base::const_iterator;
229 // parasoft-end-suppress AUTOSAR-A2_10_1-d "False positive: does not hide anything."
230
231 // parasoft-begin-suppress CERT_C-EXP37-b-3 "False positive: The rule does not mention naming all parameters"
232 /// @brief The function pointer type of the element accessor
233 using element_op_type = detail::character& (*)(string_ptr, size_type);
234 /// @brief The function pointer type of the at operation
235 using at_op_type = detail::character& (*)(string_ptr, size_type);
236 /// @brief The function pointer type of the front operation
237 using front_op_type = detail::character& (*)(string_ptr);
238 /// @brief The function pointer type of the back operation
239 using back_op_type = detail::character& (*)(string_ptr);
240 /// @brief The function pointer type of the begin operation
241 using begin_op_type = iterator (*)(string_ptr);
242 /// @brief The function pointer type of the end operation
243 using end_op_type = iterator (*)(string_ptr);
244 /// @brief The function pointer type of the to_string_view operation
245 using to_string_view_op_type = string_view (*)(string_ptr);
246 /// @brief The function pointer type of the assign operation
247 using assign_op_type = string_ptr (*)(string_ptr, string_view);
248 /// @brief The function pointer type of the append operation
249 using append_op_type = string_ptr (*)(string_ptr, string_view);
250 /// @brief The function pointer type of the append count char operation
251 using append_count_char_op_type = string_ptr (*)(string_ptr, size_type, detail::character);
252 /// @brief The function pointer type of the erase operation
253 using erase_op_type = string_ptr (*)(string_ptr, size_type, size_type);
254 /// @brief The function pointer type of the erase by iterator operation
255 using erase_it_op_type = iterator (*)(string_ptr, const_iterator, const_iterator);
256 // parasoft-end-suppress CERT_C-EXP37-b-3 "False positive: The rule does not mention naming all parameters"
257
258 /// @brief The pointer to the object holding the const operations
259 const_operations const* const_ops;
260 /// @brief The function pointer of the element accessor
261 element_op_type element;
262 /// @brief The function pointer of the at operation
263 at_op_type at;
264 /// @brief The function pointer of the front operation
265 front_op_type front;
266 /// @brief The function pointer of the back operation
267 back_op_type back;
268 /// @brief The function pointer of the begin iterator
269 begin_op_type begin;
270 /// @brief The function pointer of the end iterator
271 end_op_type end;
272 /// @brief The function pointer of the to_string_view operation
273 to_string_view_op_type to_string_view;
274 /// @brief The function pointer of the assign operation
275 assign_op_type assign;
276 /// @brief The function pointer of the append operation
277 append_op_type append;
278 /// @brief The function pointer of the append count char operation
279 append_count_char_op_type append_count_char;
280 /// @brief The function pointer of the erase operation
281 erase_op_type erase;
282 /// @brief The function pointer of the erase by iterator operation
283 erase_it_op_type erase_it;
284};
285
286/// @brief Implementation of the operations of a specific size
287/// @tparam MaxSize The maximum capacity of the string, _not_ including the null terminator
288template <std::size_t MaxSize>
289class operations_impl {
290 public:
291 /// @brief The type of the underlying string
292 using this_string = inline_string<MaxSize>;
293 /// @brief The type of a pointer to the base class of the underlying string
294 using string_ptr = inline_string_detail::inline_string_base*;
295
296 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: does not hide anything."
297 /// @brief The type of a size at the base class
298 using size_type = operations::size_type;
299 /// @brief The type of an iterator at the base class
300 using iterator = operations::iterator;
301 /// @brief The type of a const iterator at the base class
302 using const_iterator = operations::const_iterator;
303 // parasoft-end-suppress AUTOSAR-A2_10_1-d "False positive: does not hide anything."
304
305 /// @brief Cast base class pointer back to the underlying string type
306 /// @param ptr The base class pointer
307 /// @return The pointer as the underlying string type
308 static constexpr auto string(string_ptr ptr) noexcept -> this_string* {
309 return static_cast<inline_string<MaxSize>*>(ptr);
310 }
311
312 /// @brief Retrieve the @c index -th character in the string
313 /// @param ptr The base class pointer
314 /// @param index The index of the character to retrieve
315 /// @return A reference to that character
316 static constexpr auto do_element(string_ptr ptr, size_type index) noexcept -> detail::character& {
317 return (*string(ptr))[index];
318 }
319 /// @brief Retrieve the @c index -th character in the string
320 /// @tparam AreExceptionsEnabled Used to disable this overload if exceptions are not enabled.
321 /// @param ptr The base class pointer
322 /// @param index The index of the character to retrieve
323 /// @return A reference to that character
324 template <
325 bool AreExceptionsEnabled = detail::are_exceptions_enabled::value,
326 constraints<std::enable_if_t<AreExceptionsEnabled>> = nullptr>
327 static constexpr auto do_at(string_ptr ptr, size_type index) -> detail::character& {
328 return string(ptr)->at(index);
329 }
330 /// @brief When exceptions are disabled, invoking this is a precondition violation.
331 /// @tparam AreExceptionsEnabled Used to enable this overload if exceptions are not enabled.
332 /// @return Never returns
333 template <
334 bool AreExceptionsEnabled = detail::are_exceptions_enabled::value,
335 constraints<std::enable_if_t<!AreExceptionsEnabled>> = nullptr>
336 ARENE_NORETURN static auto do_at(string_ptr, std::size_t) -> detail::character& {
337 ARENE_INVARIANT_UNREACHABLE("do_at() called when exceptions are disabled");
338 }
339
340 /// @brief Get the first character in the string
341 /// @param ptr The base class pointer
342 /// @return A reference to the first character
343 static constexpr auto do_front(string_ptr ptr) noexcept -> detail::character& { return string(ptr)->front(); }
344 /// @brief Get the last character in the string
345 /// @param ptr The base class pointer
346 /// @return A reference to the last character
347 static constexpr auto do_back(string_ptr ptr) noexcept -> detail::character& { return string(ptr)->back(); }
348
349 /// @brief Iterator to the first position in the string
350 /// @param ptr The base class pointer
351 /// @return An iterator to the first element if not empty, @c end() otherwise
352 static constexpr auto do_begin(string_ptr ptr) noexcept -> iterator { return string(ptr)->begin(); }
353 /// @brief The one-past-the-last position in the string
354 /// @param ptr The base class pointer
355 /// @return An iterator to the one-past-the-last position in the string
356 static constexpr auto do_end(string_ptr ptr) noexcept -> iterator { return string(ptr)->end(); }
357
358 /// @brief Convert to string view
359 /// @param ptr The base class pointer
360 /// @return A string_view object referencing the data
361 static constexpr auto do_to_string_view(string_ptr ptr) noexcept -> string_view {
362 return {string(ptr)->data(), string(ptr)->size()};
363 }
364
365 /// @brief Assign from a string_view
366 /// @param ptr The source string
367 /// @param rhs The string to append
368 /// @return A pointer to the underlying object as the base class
369 static constexpr auto do_assign(string_ptr ptr, string_view rhs) noexcept -> string_ptr {
370 return &string(ptr)->assign(rhs);
371 }
372
373 /// @brief Append a string to the current string
374 /// @param ptr The source string
375 /// @param rhs The string to append
376 /// @return A pointer to the underlying object as the base class
377 static constexpr auto do_append(string_ptr ptr, string_view rhs) noexcept -> string_ptr {
378 return &string(ptr)->append(rhs);
379 }
380 /// @brief Append the specified number of copies of a character to the string
381 /// @param ptr The source string
382 /// @param count The number of characters to append
383 /// @param chr The character to append
384 /// @return A pointer to the underlying object as the base class
385 static constexpr auto do_append_count_char(string_ptr ptr, size_type count, detail::character chr) noexcept
386 -> string_ptr {
387 return &string(ptr)->append(count, chr);
388 }
389
390 /// @brief Erase the specified number of characters in the string starting at the specified position.
391 /// @param ptr The source string
392 /// @param pos The position of the characters to remove. If @c >size() is a noop.
393 /// @param count The maximum number of characters to remove.
394 /// @return A reference to this object
395 static constexpr auto do_erase(string_ptr ptr, size_type pos, size_type count) noexcept -> string_ptr {
396 return &string(ptr)->erase(pos, count);
397 }
398 /// @brief Erase the characters in the specified range.
399 /// @param ptr The source string
400 /// @param first The start of the range
401 /// @param last The end of the range
402 /// @return An iterator referring to the character after the removed range, or @c end()
403 static constexpr auto do_erase_it(string_ptr ptr, const_iterator first, const_iterator last) noexcept -> iterator {
404 return string(ptr)->erase(first, last);
405 }
406};
407
408/// @brief Instance of a holder of the operations of a specific size
409/// @tparam MaxSize The maximum capacity of the string, _not_ including the null terminator
410template <std::size_t MaxSize>
411extern constexpr operations string_operations{
412 &const_string_operations<MaxSize>,
413 &operations_impl<MaxSize>::do_element,
414 &operations_impl<MaxSize>::do_at,
415 &operations_impl<MaxSize>::do_front,
416 &operations_impl<MaxSize>::do_back,
417 &operations_impl<MaxSize>::do_begin,
418 &operations_impl<MaxSize>::do_end,
419 &operations_impl<MaxSize>::do_to_string_view,
420 &operations_impl<MaxSize>::do_assign,
421 &operations_impl<MaxSize>::do_append,
422 &operations_impl<MaxSize>::do_append_count_char,
423 &operations_impl<MaxSize>::do_erase,
424 &operations_impl<MaxSize>::do_erase_it,
425};
426
427/// @brief Passkey type for internal access
428class ref_passkey {
429 /// @brief Prevent construction from @c {}
430 explicit ref_passkey() = default;
431 // parasoft-begin-suppress AUTOSAR-A11_3_1-a "Passkey idiom permitted by A11-3-1 Permit #1"
432 /// @brief friend declaration to allow this class to construct the passkey
434 // parasoft-end-suppress AUTOSAR-A11_3_1-a "Passkey idiom permitted by A11-3-1 Permit #1"
435};
436
437} // namespace inline_string_reference_detail
438
439/// @brief A reference class to an inline_string object, with size-erased type
441 /// @brief A pointer to the underlying object as the base class
442 inline_string_detail::inline_string_base* string_ptr_;
443 /// @brief A pointer to the struct holding operation implementations
444 inline_string_reference_detail::operations const* op_ptrs_;
445
446 public:
447 /// @brief The type of the base class
449
450 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: does not hide anything."
451 /// @brief The type of a size at the base class
453 /// @brief The type of an iterator at the base class
455 /// @brief The type of a const iterator at the base class
457 // parasoft-end-suppress AUTOSAR-A2_10_1-d "False positive: does not hide anything."
458
459 /// @brief Construct a reference to the supplied inline_string
460 /// @tparam MaxSize The maximum capacity of the string, _not_ including the null terminator
461 /// @param str Reference to the inline_string
462 template <std::size_t MaxSize>
467
468 /// @brief Return a pointer to the NUL-terminated string held in @c *this
469 /// @return a pointer to the NUL-terminated string held in @c *this
470 ARENE_NODISCARD constexpr auto c_str() const noexcept -> detail::raw_c_string {
472 }
473 /// @brief Return a pointer to the NUL-terminated string held in @c *this
474 /// @return A pointer to the NUL-terminated string held in @c *this
475 ARENE_NODISCARD constexpr auto data() const noexcept -> detail::raw_c_string {
477 }
478
479 /// @brief Get the length of the string
480 /// @return The number of characters in the string, non-inclusive of the null-terminator
481 constexpr auto size() const noexcept -> size_type { return op_ptrs_->const_ops->size(string_ptr_); }
482
483 /// @brief The maximum length of the string
484 /// @return size_type @c MaxSize
485 constexpr auto capacity() const noexcept -> size_type { return op_ptrs_->const_ops->capacity(string_ptr_); }
486
487 /// @brief Check if the string is empty
488 /// @return @c true if the string is empty, @c false otherwise
489 constexpr auto empty() const noexcept -> bool { return op_ptrs_->const_ops->empty(string_ptr_); }
490
491 /// @brief Retrieve the @c index -th character in the string
492 /// @param index The index of the character to retrieve
493 /// @return A reference to that character
494 ARENE_NODISCARD constexpr auto operator[](size_type const index) const noexcept -> detail::character& {
496 }
497 /// @brief Retrieve the @c index -th character in the string
498 /// @tparam AreExceptionsEnabled Used to disable this overload if exceptions are not enabled.
499 /// @param index The index of the character to retrieve
500 /// @return A reference to that character
501 template <
504 constexpr auto at(size_type const index) const -> detail::character& {
505 return op_ptrs_->at(string_ptr_, index);
506 }
507
508 /// @brief Get the first character in the string
509 /// @return A reference to the first character
510 constexpr auto front() const noexcept -> detail::character& { return op_ptrs_->front(string_ptr_); }
511 /// @brief Get the last character in the string
512 /// @return A reference to the last character
513 constexpr auto back() const noexcept -> detail::character& { return op_ptrs_->back(string_ptr_); }
514
515 /// @brief Return an iterator to the first position in the string
516 /// @return An iterator to the first element if not empty, @c end() otherwise
517 constexpr auto begin() const noexcept -> iterator { return op_ptrs_->begin(string_ptr_); }
518 /// @brief The one-past-the-last position in the string
519 /// @return An iterator to the one-past-the-last position in the string
520 constexpr auto end() const noexcept -> iterator { return op_ptrs_->end(string_ptr_); }
521
522 /// @brief Convert to string view
523 /// @return A string_view object referencing the data
524 constexpr auto to_string_view() const noexcept -> string_view { return op_ptrs_->to_string_view(string_ptr_); }
525
526 /// @brief Assign from a string_view
527 /// @param rhs The string to append
528 /// @return A reference to this object
529 constexpr auto assign(string_view const rhs) const noexcept -> inline_string_reference const& {
531 return *this;
532 }
533
534 /// @brief Append a string to the current string
535 /// @param rhs The string to append
536 /// @return A reference to this object
537 constexpr auto append(string_view const rhs) const noexcept -> inline_string_reference const& {
539 return *this;
540 }
541 /// @brief Append the specified number of copies of a character to the string
542 /// @param count The number of characters to append
543 /// @param chr The character to append
544 /// @return A reference to this object
545 constexpr auto append(size_type const count, detail::character const chr) const noexcept
546 -> inline_string_reference const& {
548 return *this;
549 }
550
551 /// @brief Append a string to the current string
552 /// @param rhs The string to append
553 /// @return A reference to this object
554 constexpr auto operator+=(string_view const rhs) const noexcept -> inline_string_reference const& {
555 return this->append(rhs);
556 }
557 /// @brief Append a character to the current string
558 /// @param rhs The character to append
559 /// @return A reference to this object
560 constexpr auto operator+=(detail::character const rhs) const noexcept -> inline_string_reference const& {
561 return this->append(string_view{&rhs, 1U});
562 }
563
564 /// @brief Append a string to the current string
565 /// @param rhs The string to append
566 /// @return A reference to this object
567 constexpr auto push_back(string_view const rhs) const noexcept -> inline_string_reference const& {
568 return this->operator+=(rhs);
569 }
570 /// @brief Append a character to the current string
571 /// @param rhs The character to append
572 /// @return A reference to this object
573 constexpr auto push_back(detail::character const rhs) const noexcept -> inline_string_reference const& {
574 return this->operator+=(rhs);
575 }
576
577 /// @brief Erase the specified number of characters in the string starting at the specified position.
578 /// @param pos The position of the characters to remove. If @c pos>size() this is a noop.
579 /// @param count The maximum number of characters to remove.
580 /// @return A reference to this object
581 constexpr auto erase(size_type const pos, size_type const count) const noexcept -> inline_string_reference const& {
583 return *this;
584 }
585 /// @brief Erase the characters in the specified range.
586 /// @param first The start of the range
587 /// @param last The end of the range
588 /// @return An iterator referring to the character after the removed range, or @c end()
589 constexpr auto erase(const_iterator const first, const_iterator const last) const noexcept -> iterator {
591 }
592
593 /// @brief Compare two strings for lexicographical ordering, forwarded to string_view's
594 /// @param lhs The first string representation
595 /// @param rhs The second string representation
596 /// @return strong_ordering equivalent to string_view's 3 way compare result
597 ARENE_NODISCARD static constexpr auto
601 /// @brief Compare two strings for lexicographical ordering, forwarded to string_view's
602 /// @param lhs The first string representation
603 /// @param rhs The second string representation
604 /// @return strong_ordering equivalent to string_view's 3 way compare result
605 ARENE_NODISCARD static constexpr auto
609
610 /// @brief Get a pointer to the underlying string object pointer
611 /// @return A pointer to the underlying string object pointer
616
617 /// @brief Get a pointer to the struct holding const operation implementations
618 /// @return A pointer to the struct holding const operation implementations
623};
624
625// parasoft-begin-suppress AUTOSAR-A12_1_5-a "False positive: there is no common constructor to delegate to."
626/// @brief A const reference class to an inline_string object, with size-erased type
628 /// @brief A pointer to the underlying string object
629 inline_string_detail::inline_string_base const* string_ptr_;
630 /// @brief A pointer to the struct holding function pointers to the const operation implementations
631 inline_string_reference_detail::const_operations const* const_op_ptrs_;
632
633 public:
634 /// @brief The type of the base class
636
637 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: does not hide anything."
638 /// @brief The type of a size at the base class
640 /// @brief The type of a const iterator at the base class
642 // parasoft-end-suppress AUTOSAR-A2_10_1-d "False positive: does not hide anything."
643
644 /// @brief Construct a const reference to the supplied inline_string
645 /// @tparam MaxSize The maximum capacity of the string, _not_ including the null terminator
646 /// @param str Const reference to the inline_string
647 template <std::size_t MaxSize>
652
653 /// @brief Construct a const reference out of a non-const one
654 /// @param ref The non-const reference class
659
660 /// @brief Return a pointer to the NUL-terminated string held in @c *this
661 /// @return A pointer to the NUL-terminated string held in @c *this
662 ARENE_NODISCARD constexpr auto c_str() const noexcept -> detail::raw_c_string {
664 }
665 /// @brief Return a pointer to the NUL-terminated string held in @c *this
666 /// @return A pointer to the NUL-terminated string held in @c *this
667 ARENE_NODISCARD constexpr auto data() const noexcept -> detail::raw_c_string {
669 }
670
671 /// @brief Get the length of the string
672 /// @return The number of characters in the string, non-inclusive of the null-terminator
673 constexpr auto size() const noexcept -> size_type { return const_op_ptrs_->size(string_ptr_); }
674
675 /// @brief The maximum length of the string
676 /// @return size_type @c MaxSize
677 constexpr auto capacity() const noexcept -> size_type { return const_op_ptrs_->capacity(string_ptr_); }
678
679 /// @brief Check if the string is empty
680 /// @return @c true if the string is empty, @c false otherwise
681 constexpr auto empty() const noexcept -> bool { return const_op_ptrs_->empty(string_ptr_); }
682
683 /// @brief Retrieve the @c index -th character in the string
684 /// @param index The index of the character to retrieve
685 /// @return A reference to that character
686 ARENE_NODISCARD constexpr auto operator[](size_type const index) const noexcept -> detail::character const& {
688 }
689 /// @brief Retrieve the @c index -th character in the string
690 /// @tparam AreExceptionsEnabled Used to disable this overload if exceptions are not enabled.
691 /// @param index The index of the character to retrieve
692 /// @return A reference to that character
693 template <
696 constexpr auto at(size_type const index) const -> detail::character const& {
698 }
699
700 /// @brief Get the first character in the string
701 /// @return A reference to the first character
702 constexpr auto front() const noexcept -> detail::character const& { return const_op_ptrs_->front(string_ptr_); }
703 /// @brief Get the last character in the string
704 /// @return A reference to the last character
705 constexpr auto back() const noexcept -> detail::character const& { return const_op_ptrs_->back(string_ptr_); }
706
707 /// @brief Return an iterator to the first position in the string
708 /// @return A const iterator to the first element if not empty, @c end() otherwise
709 constexpr auto begin() const noexcept -> const_iterator { return const_op_ptrs_->begin(string_ptr_); }
710 /// @brief The one-past-the-last position in the string
711 /// @return A const iterator to one-past-the-last position in the string
712 constexpr auto end() const noexcept -> const_iterator { return const_op_ptrs_->end(string_ptr_); }
713
714 /// @brief Convert to string view
715 /// @return string_view A string_view object referencing the data
716 constexpr auto to_string_view() const noexcept -> string_view { return const_op_ptrs_->to_string_view(string_ptr_); }
717
718 /// @brief Compare two strings for lexicographical ordering, forwarded to string_view's
719 /// @param lhs The first string representation
720 /// @param rhs The second string representation
721 /// @return strong_ordering equivalent to string_view's 3 way compare result
728 /// @brief Compare two strings for lexicographical ordering, forwarded to string_view's
729 /// @param lhs The first string representation
730 /// @param rhs The second string representation
731 /// @return strong_ordering equivalent to string_view's 3 way compare result
738 /// @brief Compare two strings for lexicographical ordering, forwarded to string_view's
739 /// @param lhs The first string representation
740 /// @param rhs The second string representation
741 /// @return strong_ordering equivalent to string_view's 3 way compare result
742 ARENE_NODISCARD static constexpr auto
746};
747// parasoft-end-suppress AUTOSAR-A12_1_5-a "False positive: there is no common constructor to delegate to."
748
749} // namespace base
750} // namespace arene
751
752#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_STRINGS_INLINE_STRING_REFERENCE_HPP_
A const reference class to an inline_string object, with size-erased type.
Definition inline_string_reference.hpp:627
A reference class to an inline_string object, with size-erased type.
Definition inline_string_reference.hpp:440
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10