gw  1.0.0
A bunch of small C++ utilities
Loading...
Searching...
No Matches
inplace_string.hpp
1// Copyright (c) 2023 Martin Stump
2// SPDX-License-Identifier: BSL-1.0
3
4#pragma once
5
6#include <algorithm>
7#include <array>
8#include <concepts>
9#include <cstddef>
10#include <format>
11#include <iostream>
12#include <iterator>
13#include <ostream>
14#include <ranges>
15#include <stdexcept>
16#include <string>
17#include <string_view>
18#include <utility>
19
21namespace gw {
22
24//
29template <std::size_t N, class CharT, class Traits = std::char_traits<CharT>>
31 public:
32 using traits_type = Traits;
33 using value_type = CharT;
34 using size_type = std::size_t;
35 using difference_type = std::ptrdiff_t;
37 using const_reference = const value_type&;
39 using const_pointer = const value_type*;
41 using const_iterator = const value_type*;
42 using reverse_iterator = std::reverse_iterator<iterator>;
43 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
44
47 std::array<value_type, N + 1U> m_data;
48
49 // NOLINTNEXTLINE(readability-identifier-naming)
50 static constexpr size_type npos = -1;
51
54
56 template <std::size_t N2>
57 // NOLINTNEXTLINE
59 requires(N2 <= N + 1)
60 : m_data{} {
61 traits_type::copy(data(), str, N2 - 1);
62 }
63
69 if (count > max_size()) {
70 throw std::length_error{
71 std::format("basic_inplace_string::basic_inplace_string: count (which is {}) > max_size (which is {})", count,
72 max_size())};
73 }
74 std::ranges::fill_n(begin(), count, ch);
75 }
76
80 constexpr explicit basic_inplace_string(const value_type* str) : m_data{} {
81 const auto str_size = traits_type::length(str);
82
83 if (str_size > max_size()) {
84 throw std::length_error{
85 std::format("basic_inplace_string::basic_inplace_string: str_size (which is {}) > max_size (which is {})",
86 str_size, max_size())};
87 }
88
89 traits_type::copy(begin(), str, str_size);
90 }
91
96 constexpr explicit basic_inplace_string(const value_type* str, size_type count) : m_data{} {
97 if (count > max_size()) {
98 throw std::length_error{
99 std::format("basic_inplace_string::basic_inplace_string: count (which is {}) > max_size (which is {})", count,
100 max_size())};
101 }
102 traits_type::copy(begin(), str, count);
103 }
104
110 template <std::input_iterator InputIt>
112 const auto str_size = std::ranges::distance(first, last);
113
114 if (str_size > max_size()) {
115 throw std::length_error{
116 std::format("basic_inplace_string::basic_inplace_string: str_size (which is {}) > max_size (which is {})",
117 str_size, max_size())};
118 }
119
120 std::ranges::copy(first, last, begin());
121 }
122
126 constexpr explicit basic_inplace_string(const std::basic_string_view<value_type, traits_type>& str)
128
132 template <std::ranges::range R>
133 requires(!std::is_convertible_v<const R&, std::basic_string_view<value_type, traits_type>> &&
134 std::convertible_to<std::ranges::range_value_t<R>, value_type>)
135 constexpr explicit basic_inplace_string(const R& range)
136 : basic_inplace_string(std::ranges::begin(range), std::ranges::end(range)) {}
137
139 constexpr basic_inplace_string(const basic_inplace_string& other) noexcept = default;
140
142 constexpr basic_inplace_string(basic_inplace_string&& other) noexcept = default;
143
146
149
152
158 return pos < size()
159 ? m_data[pos]
160 : throw std::out_of_range{std::format(
161 "basic_inplace_string::at: pos (which is {}) >= max_size (which is {})", pos, max_size())};
162 }
163
168 constexpr auto at(size_type pos) const -> const_reference {
169 return pos < size()
170 ? m_data[pos]
171 : throw std::out_of_range{std::format(
172 "basic_inplace_string::at: pos (which is {}) >= max_size (which is {})", pos, max_size())};
173 }
174
178 constexpr auto operator[](size_type pos) noexcept -> reference { return m_data[pos]; }
179
183 constexpr auto operator[](size_type pos) const noexcept -> const_reference { return m_data[pos]; }
184
187 constexpr auto front() noexcept -> reference { return m_data[0]; }
188
191 constexpr auto front() const noexcept -> const_reference { return m_data[0]; }
192
195 constexpr auto back() noexcept -> reference { return m_data[size() - 1]; }
196
199 constexpr auto back() const noexcept -> const_reference { return m_data[size() - 1]; }
200
203 constexpr auto data() noexcept -> pointer { return m_data.data(); }
204
207 constexpr auto data() const noexcept -> const_pointer { return m_data.data(); }
208
211 constexpr auto c_str() const noexcept -> const_pointer { return m_data.data(); }
212
215 constexpr explicit operator std::basic_string_view<value_type, traits_type>() const noexcept {
216 return {data(), size()};
217 }
218
221 constexpr auto view() const noexcept -> std::basic_string_view<value_type, traits_type> { return {data(), size()}; }
222
225 constexpr auto begin() noexcept -> iterator { return data(); }
226
229 constexpr auto begin() const noexcept -> const_iterator { return data(); }
230
233 constexpr auto cbegin() const noexcept -> const_iterator { return data(); }
234
237 constexpr auto end() noexcept -> iterator { return std::ranges::next(data(), size()); }
238
241 constexpr auto end() const noexcept -> const_iterator { return std::ranges::next(data(), size()); }
242
245 constexpr auto cend() const noexcept -> const_iterator { return std::ranges::next(data(), size()); }
246
249 constexpr auto rbegin() noexcept -> reverse_iterator { return reverse_iterator{end()}; }
250
254
258
261 constexpr auto rend() noexcept -> reverse_iterator { return reverse_iterator{begin()}; }
262
266
270
273 [[nodiscard]] constexpr auto empty() const noexcept -> bool { return size() == 0U; }
274
277 [[nodiscard]] constexpr auto size() const noexcept -> size_type { return traits_type::length(data()); }
278
281 [[nodiscard]] constexpr auto length() const noexcept -> size_type { return size(); }
282
285 [[nodiscard]] inline constexpr auto max_size() const noexcept -> size_type { return N; }
286
291 constexpr void reserve(size_type new_cap) {
292 if (new_cap > max_size()) {
293 throw std::length_error{std::format(
294 "basic_inplace_string::reserve: new_cap (which is {}) > max_size (which is {})", new_cap, max_size())};
295 }
296 }
297
300 [[nodiscard]] constexpr auto capacity() const noexcept -> size_type { return max_size(); }
301
304 constexpr void shrink_to_fit() {}
305
307 constexpr void clear() noexcept { m_data[0] = value_type{}; }
308
314 constexpr void insert(size_type index, size_type count, CharT ch) {
315 const auto new_size = size() + count;
316 if (new_size > max_size()) {
317 throw std::length_error{std::format(
318 "basic_inplace_string::insert: new_size (which is {}) > max_size (which is {})", new_size, max_size())};
319 }
320 std::ranges::copy_backward(std::ranges::next(begin(), index), end(), std::ranges::next(end(), count));
321 std::ranges::fill_n(std::ranges::next(begin(), index), count, ch);
322 m_data[new_size] = value_type{}; // Ensure null termination
323 }
324
331 const auto str_size = traits_type::length(str);
332 return insert(index, str, str_size);
333 }
334
342 const auto new_size = size() + count;
343 if (new_size > max_size()) {
344 throw std::length_error{std::format(
345 "basic_inplace_string::insert: new_size (which is {}) > max_size (which is {})", new_size, max_size())};
346 }
347 std::ranges::copy_backward(std::ranges::next(begin(), index), end(), std::ranges::next(end(), count));
348 traits_type::copy(std::ranges::next(begin(), index), str, count);
349 m_data[new_size] = value_type{}; // Ensure null termination
350 return *this;
351 }
352
359 template <std::size_t N2>
361 return insert(index, str.data(), str.size());
362 }
363
369
376 const auto index = std::ranges::distance(cbegin(), pos);
377 insert(index, count, ch);
378 return std::ranges::next(begin(), index);
379 }
380
388 template <std::input_iterator InputIt>
390 requires std::convertible_to<std::iter_value_t<InputIt>, value_type>
391 {
392 const auto index = std::ranges::distance(cbegin(), pos);
393 const auto count = std::ranges::distance(first, last);
394 const auto new_size = size() + count;
395 if (new_size > max_size()) {
396 throw std::length_error{std::format(
397 "basic_inplace_string::insert: new_size (which is {}) > max_size (which is {})", new_size, max_size())};
398 }
399 std::ranges::copy_backward(std::ranges::next(begin(), index), end(), std::ranges::next(end(), count));
400 std::ranges::copy(first, last, std::ranges::next(begin(), index));
401 m_data[new_size] = value_type{}; // Ensure null termination
402 return std::ranges::next(begin(), index);
403 }
404
411 template <std::ranges::input_range R>
413 requires std::convertible_to<std::ranges::range_value_t<R>, value_type>
414 {
415 return insert(pos, std::ranges::begin(range), std::ranges::end(range));
416 }
417
422 constexpr void erase(size_type index = 0U, size_type count = npos) {
423 if (index >= size()) {
424 throw std::out_of_range{
425 std::format("basic_inplace_string::erase: index (which is {}) >= size (which is {})", index, size())};
426 }
427 const auto no_of_chars_to_erase = std::ranges::min(count, size() - index);
428 const auto new_size = size() - no_of_chars_to_erase;
429 std::ranges::copy(std::ranges::next(begin(), index + count), end(), std::ranges::next(begin(), index));
430 m_data[new_size] = value_type{}; // Ensure null termination
431 }
432
436 constexpr void push_back(value_type ch) {
437 const auto new_size = size() + 1;
438 if (new_size > max_size()) {
439 throw std::length_error{std::format(
440 "basic_inplace_string::push_back: new_size (which is {}) > max_size (which is {})", new_size, max_size())};
441 }
442 m_data[size()] = ch;
443 m_data[new_size] = value_type{}; // Ensure null termination
444 }
445
447 constexpr void pop_back() noexcept { m_data[size() - 1] = value_type{}; }
448
453 template <std::size_t N2>
455 const auto new_size = size() + str.size();
456 if (new_size > max_size()) {
457 throw std::length_error{std::format(
458 "basic_inplace_string::append: new_size (which is {}) > max_size (which is {})", new_size, max_size())};
459 }
460 traits_type::copy(end(), str.data(), str.size());
461 m_data[new_size] = value_type{}; // Ensure null termination
462 }
463
468 template <std::size_t N2>
470 const auto new_size = size() + str.size();
471 if (new_size > max_size()) {
472 throw std::length_error{std::format(
473 "basic_inplace_string::operator+=: new_size (which is {}) > max_size (which is {})", new_size, max_size())};
474 }
475 traits_type::copy(end(), str.data(), str.size());
476 m_data[new_size] = value_type{}; // Ensure null termination
477 return *this;
478 }
479
483 constexpr void resize(size_type count) {
484 if (count > max_size()) {
485 throw std::length_error{
486 std::format("basic_inplace_string::resize: count (which is {}) > max_size (which is {})", count, max_size())};
487 }
488 m_data[count] = value_type{}; // Ensure null termination
489 }
490
495 constexpr void resize(size_type count, value_type ch) {
496 if (count > max_size()) {
497 throw std::length_error{
498 std::format("basic_inplace_string::resize: count (which is {}) > max_size (which is {})", count, max_size())};
499 }
500 if (count > size()) {
501 std::ranges::fill_n(end(), count - size(), ch);
502 }
503 m_data[count] = value_type{}; // Ensure null termination
504 }
505
508 constexpr void swap(basic_inplace_string& other) noexcept {
509 using std::swap;
510 swap(m_data, other.m_data);
511 }
512
518 template <std::size_t N2>
521 return find(str.view(), pos);
522 }
523
528 constexpr auto find(std::basic_string_view<value_type, traits_type> str,
530 return view().find(str, pos);
531 }
532
538 constexpr auto find(const value_type* str, size_type pos, size_type count) const noexcept -> size_type {
539 return view().find(str, pos, count);
540 }
541
546 constexpr auto find(const value_type* str, size_type pos = 0) const noexcept -> size_type {
547 return view().find(str, pos);
548 }
549
554 constexpr auto find(value_type ch, size_type pos = 0) const noexcept -> size_type { return view().find(ch, pos); }
555
561 template <std::size_t N2>
563 size_type pos = npos) const noexcept -> size_type {
564 return rfind(str.view(), pos);
565 }
566
571 constexpr auto rfind(std::basic_string_view<value_type, traits_type> str,
572 size_type pos = npos) const noexcept -> size_type {
573 return view().rfind(str, pos);
574 }
575
581 constexpr auto rfind(const value_type* str, size_type pos, size_type count) const noexcept -> size_type {
582 return view().rfind(str, pos, count);
583 }
584
589 constexpr auto rfind(const value_type* str, size_type pos = npos) const noexcept -> size_type {
590 return view().rfind(str, pos);
591 }
592
597 constexpr auto rfind(value_type ch, size_type pos = npos) const noexcept -> size_type {
598 return view().rfind(ch, pos);
599 }
600
606 template <std::size_t N2>
611
616 constexpr auto find_first_of(std::basic_string_view<value_type, traits_type> str,
618 return view().find_first_of(str, pos);
619 }
620
626 return view().find_first_of(str, pos);
627 }
628
634 template <std::size_t N2>
635 friend constexpr auto operator+(const basic_inplace_string& lhs,
638 const auto new_size = lhs.size() + rhs.size();
640 traits_type::copy(result.data(), lhs.data(), lhs.size());
641 traits_type::copy(std::ranges::next(result.data(), lhs.size()), rhs.data(), rhs.size());
642 result[new_size] = value_type{}; // Ensure null termination
643 return result;
644 }
645
650 friend constexpr auto operator==(const basic_inplace_string& lhs, const basic_inplace_string& rhs) noexcept -> bool {
651 return std::ranges::equal(lhs.begin(), lhs.end(), rhs.begin());
652 }
653
658 friend constexpr auto operator==(const basic_inplace_string& lhs,
659 std::basic_string_view<value_type, traits_type> rhs) noexcept -> bool {
660 return std::ranges::equal(lhs.begin(), lhs.end(), rhs.begin());
661 }
662
667 friend constexpr auto operator==(std::basic_string_view<value_type, traits_type> lhs,
668 const basic_inplace_string& rhs) noexcept -> bool {
669 return rhs == lhs;
670 }
671
676 friend constexpr auto operator==(const basic_inplace_string& lhs, const value_type* rhs) noexcept -> bool {
677 return traits_type::compare(lhs.data(), rhs, traits_type::length(rhs)) == 0;
678 }
679
684 friend constexpr auto operator==(const value_type* lhs, const basic_inplace_string& rhs) noexcept -> bool {
685 return rhs == lhs;
686 }
687
692 friend constexpr auto operator!=(const basic_inplace_string& lhs, const basic_inplace_string& rhs) noexcept -> bool {
693 return !(lhs == rhs);
694 }
695
700 friend constexpr auto operator!=(const basic_inplace_string& lhs,
701 std::basic_string_view<value_type, traits_type> rhs) noexcept -> bool {
702 return !(lhs == rhs);
703 }
704
709 friend constexpr auto operator!=(std::basic_string_view<value_type, traits_type> lhs,
710 const basic_inplace_string& rhs) noexcept -> bool {
711 return !(lhs == rhs);
712 }
713
718 friend constexpr auto operator!=(const basic_inplace_string& lhs, const value_type* rhs) noexcept -> bool {
719 return !(lhs == rhs);
720 }
721
726 friend constexpr auto operator!=(const value_type* lhs, const basic_inplace_string& rhs) noexcept -> bool {
727 return !(lhs == rhs);
728 }
729
734 friend inline auto operator<<(std::basic_ostream<value_type, traits_type>& ostream,
735 const basic_inplace_string& rhs) -> std::basic_ostream<value_type, traits_type>& {
736 return ostream << rhs.view();
737 }
738
743 friend inline auto operator>>(std::basic_istream<value_type, traits_type>& istream,
744 basic_inplace_string& rhs) -> std::basic_istream<value_type, traits_type>& {
745 const auto new_size = rhs.size() + istream.rdbuf()->in_avail();
746 if (new_size > rhs.max_size()) {
747 throw std::length_error{
748 std::format("basic_inplace_string::operator>>: new_size (which is {}) > max_size (which is {})", new_size,
749 rhs.max_size())};
750 }
751 const auto it = std::istreambuf_iterator<value_type, traits_type>{istream};
752 const auto end = std::istreambuf_iterator<value_type, traits_type>{};
753 std::ranges::copy(it, end, rhs.end());
754 rhs[new_size] = value_type{}; // Ensure null termination
755 return istream;
756 }
757};
758
760template <typename CharT, std::size_t N>
761// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
762basic_inplace_string(const CharT (&)[N]) -> basic_inplace_string<N - 1U, CharT>;
763
765template <std::size_t N>
767
769template <std::size_t N>
771
773template <std::size_t N>
775
777template <std::size_t N>
779
780} // namespace gw
781
782namespace std {
783
785template <std::size_t N, class CharT, class Traits>
786// NOLINTNEXTLINE(cert-dcl58-cpp)
787struct hash<::gw::basic_inplace_string<N, CharT, Traits>> {
789 [[nodiscard]] auto inline operator()(const ::gw::basic_inplace_string<N, CharT, Traits>& str) const noexcept
790 -> size_t {
791 return hash<basic_string_view<CharT, Traits>>{}(static_cast<basic_string_view<CharT, Traits>>(str));
792 }
793};
794
796template <std::size_t N, class CharT, class Traits>
797// NOLINTNEXTLINE(cert-dcl58-cpp)
798struct formatter<::gw::basic_inplace_string<N, CharT, Traits>, CharT> {
800 template <class ParseContext>
801 constexpr auto parse(ParseContext& context) const -> ParseContext::iterator {
802 return context.begin();
803 }
804
806 template <class FormatContext>
807 constexpr auto format(const ::gw::basic_inplace_string<N, CharT, Traits>& str,
808 FormatContext& context) const -> FormatContext::iterator {
809 return ranges::copy(str, context.out()).out;
810 }
811};
812
813} // namespace std
A fixed-size string that stores the data in-place.
Definition inplace_string.hpp:30
friend constexpr auto operator+(const basic_inplace_string &lhs, const basic_inplace_string< N2, value_type, traits_type > &rhs) -> basic_inplace_string< N+N2, value_type, traits_type >
Concatenate two strings.
Definition inplace_string.hpp:635
std::size_t size_type
The size type.
Definition inplace_string.hpp:34
constexpr auto capacity() const noexcept -> size_type
Get the capacity of the string.
Definition inplace_string.hpp:300
const value_type * const_pointer
The const pointer type.
Definition inplace_string.hpp:39
std::reverse_iterator< const_iterator > const_reverse_iterator
The const reverse iterator type.
Definition inplace_string.hpp:43
constexpr auto find(const value_type *str, size_type pos, size_type count) const noexcept -> size_type
Find the first substring equal to the range [str, str + count).
Definition inplace_string.hpp:538
constexpr basic_inplace_string(const value_type *str, size_type count)
Construct the string with the contents of the range [str, str + count).
Definition inplace_string.hpp:96
constexpr auto end() noexcept -> iterator
Get an iterator to the end of the string.
Definition inplace_string.hpp:237
auto insert(const_iterator pos, size_type count, value_type ch) -> iterator
Insert count copies of character ch before the element (if any) pointed by pos.
Definition inplace_string.hpp:375
constexpr basic_inplace_string(const basic_inplace_string &other) noexcept=default
Copy constructor.
CharT value_type
The character type.
Definition inplace_string.hpp:33
constexpr auto operator[](size_type pos) noexcept -> reference
Get a reference to the character at the specified position.
Definition inplace_string.hpp:178
std::reverse_iterator< iterator > reverse_iterator
The reverse iterator type.
Definition inplace_string.hpp:42
constexpr auto rend() noexcept -> reverse_iterator
Get a reverse iterator to the beginning of the string.
Definition inplace_string.hpp:261
constexpr void insert(size_type index, size_type count, CharT ch)
Insert count copies of character ch at the position index.
Definition inplace_string.hpp:314
constexpr auto rfind(const value_type *str, size_type pos=npos) const noexcept -> size_type
Find the last substring equal to the character string pointed to by str.
Definition inplace_string.hpp:589
constexpr auto find(value_type ch, size_type pos=0) const noexcept -> size_type
Find the first character ch.
Definition inplace_string.hpp:554
constexpr basic_inplace_string(size_type count, value_type ch)
Construct the string with count copies of character ch.
Definition inplace_string.hpp:68
constexpr auto back() const noexcept -> const_reference
Get a const reference to the last character in the string.
Definition inplace_string.hpp:199
constexpr auto rfind(const value_type *str, size_type pos, size_type count) const noexcept -> size_type
Find the last substring equal to the range [str, str + count).
Definition inplace_string.hpp:581
constexpr auto view() const noexcept -> std::basic_string_view< value_type, traits_type >
Get a string view of the string.
Definition inplace_string.hpp:221
friend constexpr auto operator==(const basic_inplace_string &lhs, std::basic_string_view< value_type, traits_type > rhs) noexcept -> bool
Compare the string to a string view.
Definition inplace_string.hpp:658
constexpr auto cend() const noexcept -> const_iterator
Get a const iterator to the end of the string.
Definition inplace_string.hpp:245
friend auto operator<<(std::basic_ostream< value_type, traits_type > &ostream, const basic_inplace_string &rhs) -> std::basic_ostream< value_type, traits_type > &
Write the string to an output stream.
Definition inplace_string.hpp:734
constexpr void resize(size_type count, value_type ch)
Resize the string to count characters.
Definition inplace_string.hpp:495
auto insert(const_iterator pos, value_type ch) -> iterator
Insert the character ch before the element (if any) pointed by pos.
Definition inplace_string.hpp:368
constexpr auto rend() const noexcept -> const_reverse_iterator
Get a const reverse iterator to the beginning of the string.
Definition inplace_string.hpp:265
static constexpr size_type npos
The maximum value for size_type.
Definition inplace_string.hpp:50
const value_type * const_iterator
The const iterator type.
Definition inplace_string.hpp:41
constexpr auto c_str() const noexcept -> const_pointer
Get a const pointer to the underlying character array.
Definition inplace_string.hpp:211
auto insert(size_type index, const basic_inplace_string< N2, value_type, traits_type > &str) -> basic_inplace_string &
Insert the inplace string at the position index.
Definition inplace_string.hpp:360
constexpr auto rbegin() noexcept -> reverse_iterator
Get a reverse iterator to the end of the string.
Definition inplace_string.hpp:249
constexpr auto rfind(const basic_inplace_string< N2, value_type, traits_type > &str, size_type pos=npos) const noexcept -> size_type
Find the last substring equal to str.
Definition inplace_string.hpp:562
constexpr auto size() const noexcept -> size_type
Get the size of the string.
Definition inplace_string.hpp:277
constexpr basic_inplace_string() noexcept=default
Default constructor.
constexpr auto operator[](size_type pos) const noexcept -> const_reference
Get a const reference to the character at the specified position.
Definition inplace_string.hpp:183
constexpr auto empty() const noexcept -> bool
Check if the string is empty.
Definition inplace_string.hpp:273
Traits traits_type
The character traits type.
Definition inplace_string.hpp:32
constexpr void push_back(value_type ch)
Append a character to the end of the string.
Definition inplace_string.hpp:436
constexpr auto find(const basic_inplace_string< N2, value_type, traits_type > &str, size_type pos=0) const noexcept -> size_type
Find the first substring equal to str.
Definition inplace_string.hpp:519
auto insert(size_type index, const value_type *str, size_type count) -> basic_inplace_string &
Insert the characters in the range [str, str + count) at the position index.
Definition inplace_string.hpp:341
constexpr basic_inplace_string(const R &range)
Construct the string with the contents of the range.
Definition inplace_string.hpp:135
friend constexpr auto operator==(std::basic_string_view< value_type, traits_type > lhs, const basic_inplace_string &rhs) noexcept -> bool
Compare the string to a string view.
Definition inplace_string.hpp:667
constexpr auto back() noexcept -> reference
Get a reference to the last character in the string.
Definition inplace_string.hpp:195
constexpr auto insert_range(const_iterator pos, R &&range) -> iterator
Insert the characters from the range before the element (if any) pointed by pos.
Definition inplace_string.hpp:412
constexpr auto length() const noexcept -> size_type
Get the length of the string.
Definition inplace_string.hpp:281
constexpr ~basic_inplace_string() noexcept=default
Destructor.
friend constexpr auto operator==(const value_type *lhs, const basic_inplace_string &rhs) noexcept -> bool
Compares the string to a character string.
Definition inplace_string.hpp:684
constexpr auto at(size_type pos) const -> const_reference
Get a const reference to the character at the specified position.
Definition inplace_string.hpp:168
auto insert(const_iterator pos, InputIt first, InputIt last) -> iterator
Insert the characters from the range [first, last) before the element (if any) pointed by pos.
Definition inplace_string.hpp:389
auto insert(size_type index, const value_type *str) -> basic_inplace_string &
Insert the null-terminated character string pointed to by str at the position index.
Definition inplace_string.hpp:330
constexpr basic_inplace_string(const value_type *str)
Construct the string with the characters from the character string pointed to by str.
Definition inplace_string.hpp:80
friend auto operator>>(std::basic_istream< value_type, traits_type > &istream, basic_inplace_string &rhs) -> std::basic_istream< value_type, traits_type > &
Read the string from an input stream.
Definition inplace_string.hpp:743
constexpr void erase(size_type index=0U, size_type count=npos)
Erase count characters from the position index.
Definition inplace_string.hpp:422
constexpr auto find_first_of(std::basic_string_view< value_type, traits_type > str, size_type pos=0) const noexcept -> size_type
Find the first character equal to one of the characters in str.
Definition inplace_string.hpp:616
constexpr void append(const basic_inplace_string< N2, value_type, traits_type > &str)
Append a string to the end of the string.
Definition inplace_string.hpp:454
constexpr auto at(size_type pos) -> reference
Get a reference to the character at the specified position.
Definition inplace_string.hpp:157
constexpr auto front() const noexcept -> const_reference
Get a const reference to the first character in the string.
Definition inplace_string.hpp:191
constexpr auto max_size() const noexcept -> size_type
Get the maximum size of the string.
Definition inplace_string.hpp:285
constexpr auto rbegin() const noexcept -> const_reverse_iterator
Get a const reverse iterator to the end of the string.
Definition inplace_string.hpp:253
friend constexpr auto operator==(const basic_inplace_string &lhs, const basic_inplace_string &rhs) noexcept -> bool
Compare the string to another string.
Definition inplace_string.hpp:650
value_type * iterator
The iterator type.
Definition inplace_string.hpp:40
std::ptrdiff_t difference_type
The difference type.
Definition inplace_string.hpp:35
constexpr auto rfind(std::basic_string_view< value_type, traits_type > str, size_type pos=npos) const noexcept -> size_type
Find the last substring equal to str.
Definition inplace_string.hpp:571
constexpr basic_inplace_string(InputIt first, InputIt last)
Construct the string with the contents of the range [first, last).
Definition inplace_string.hpp:111
constexpr void shrink_to_fit()
Shrink the capacity of the string to fit its size.
Definition inplace_string.hpp:304
constexpr auto crbegin() const noexcept -> const_reverse_iterator
Get a const reverse iterator to the end of the string.
Definition inplace_string.hpp:257
constexpr void swap(basic_inplace_string &other) noexcept
Swap the string with another string.
Definition inplace_string.hpp:508
constexpr void clear() noexcept
Clear the contents of the string.
Definition inplace_string.hpp:307
const value_type & const_reference
The const reference type.
Definition inplace_string.hpp:37
constexpr auto find(std::basic_string_view< value_type, traits_type > str, size_type pos=0) const noexcept -> size_type
Find the first substring equal to str.
Definition inplace_string.hpp:528
constexpr auto begin() const noexcept -> const_iterator
Get a const iterator to the beginning of the string.
Definition inplace_string.hpp:229
constexpr auto rfind(value_type ch, size_type pos=npos) const noexcept -> size_type
Find the last character ch.
Definition inplace_string.hpp:597
constexpr auto end() const noexcept -> const_iterator
Get a const iterator to the end of the string.
Definition inplace_string.hpp:241
constexpr void resize(size_type count)
Resize the string to count characters.
Definition inplace_string.hpp:483
std::array< value_type, N+1U > m_data
The character array.
Definition inplace_string.hpp:47
constexpr void pop_back() noexcept
Remove the last character from the string.
Definition inplace_string.hpp:447
constexpr basic_inplace_string(const std::basic_string_view< value_type, traits_type > &str)
Construct the string with the contents of the string view.
Definition inplace_string.hpp:126
constexpr basic_inplace_string(basic_inplace_string &&other) noexcept=default
Move constructor.
constexpr auto front() noexcept -> reference
Get a reference to the first character in the string.
Definition inplace_string.hpp:187
friend constexpr auto operator==(const basic_inplace_string &lhs, const value_type *rhs) noexcept -> bool
Compares the string to a character string.
Definition inplace_string.hpp:676
constexpr auto find_first_of(const basic_inplace_string< N2, value_type, traits_type > &str, size_type pos=0) const noexcept -> size_type
Find the first character equal to one of the characters in str.
Definition inplace_string.hpp:607
value_type * pointer
The pointer type.
Definition inplace_string.hpp:38
constexpr auto find_first_of(const value_type *str, size_type pos=0) const noexcept -> size_type
Find the first character equal to one of the characters in str.
Definition inplace_string.hpp:625
constexpr void reserve(size_type new_cap)
Reserve storage for the string.
Definition inplace_string.hpp:291
value_type & reference
The reference type.
Definition inplace_string.hpp:36
constexpr auto data() const noexcept -> const_pointer
Get a const pointer to the underlying character array.
Definition inplace_string.hpp:207
constexpr auto crend() const noexcept -> const_reverse_iterator
Get a const reverse iterator to the beginning of the string.
Definition inplace_string.hpp:269
constexpr auto begin() noexcept -> iterator
Get an iterator to the beginning of the string.
Definition inplace_string.hpp:225
constexpr auto find(const value_type *str, size_type pos=0) const noexcept -> size_type
Find the first substring equal to the character string pointed to by str.
Definition inplace_string.hpp:546
consteval explicit(false) basic_inplace_string(const value_type(&str)[N2]) noexcept
Construct the string with the characters from the character string pointed to by str.
Definition inplace_string.hpp:58
constexpr auto data() noexcept -> pointer
Get a pointer to the underlying character array.
Definition inplace_string.hpp:203
constexpr auto cbegin() const noexcept -> const_iterator
Get a const iterator to the beginning of the string.
Definition inplace_string.hpp:233
GW namespace.
Definition concepts.hpp:14
STL namespace.
constexpr auto parse(ParseContext &context) const -> ParseContext::iterator
Parse the format string.
Definition inplace_string.hpp:801
constexpr auto format(const ::gw::basic_inplace_string< N, CharT, Traits > &str, FormatContext &context) const -> FormatContext::iterator
Format the inplace_string object.
Definition inplace_string.hpp:807
auto operator()(const ::gw::basic_inplace_string< N, CharT, Traits > &str) const noexcept -> size_t
Calculate the hash of the inplace_string object.
Definition inplace_string.hpp:789