29template <std::
size_t N,
class CharT,
class Traits = std::
char_traits<CharT>>
47 std::array<value_type, N + 1U>
m_data;
70 throw std::length_error{
71 std::format(
"basic_inplace_string::basic_inplace_string: count (which is {}) > max_size (which is {})",
count,
84 throw std::length_error{
85 std::format(
"basic_inplace_string::basic_inplace_string: str_size (which is {}) > max_size (which is {})",
98 throw std::length_error{
99 std::format(
"basic_inplace_string::basic_inplace_string: count (which is {}) > max_size (which is {})",
count,
110 template <std::input_iterator InputIt>
115 throw std::length_error{
116 std::format(
"basic_inplace_string::basic_inplace_string: str_size (which is {}) > max_size (which is {})",
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>)
160 :
throw std::out_of_range{std::format(
161 "basic_inplace_string::at: pos (which is {}) >= max_size (which is {})",
pos,
max_size())};
171 :
throw std::out_of_range{std::format(
172 "basic_inplace_string::at: pos (which is {}) >= max_size (which is {})",
pos,
max_size())};
215 constexpr explicit operator std::basic_string_view<value_type, traits_type>()
const noexcept {
293 throw std::length_error{std::format(
294 "basic_inplace_string::reserve: new_cap (which is {}) > max_size (which is {})",
new_cap,
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())};
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);
344 throw std::length_error{std::format(
345 "basic_inplace_string::insert: new_size (which is {}) > max_size (which is {})",
new_size,
max_size())};
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);
359 template <std::
size_t N2>
376 const auto index = std::ranges::distance(
cbegin(),
pos);
378 return std::ranges::next(
begin(), index);
388 template <std::input_iterator InputIt>
390 requires std::convertible_to<std::iter_value_t<InputIt>,
value_type>
392 const auto index = std::ranges::distance(
cbegin(),
pos);
396 throw std::length_error{std::format(
397 "basic_inplace_string::insert: new_size (which is {}) > max_size (which is {})",
new_size,
max_size())};
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));
402 return std::ranges::next(
begin(), index);
411 template <std::ranges::input_range R>
413 requires std::convertible_to<std::ranges::range_value_t<R>,
value_type>
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())};
429 std::ranges::copy(std::ranges::next(
begin(), index +
count),
end(), std::ranges::next(
begin(), index));
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())};
453 template <std::
size_t N2>
457 throw std::length_error{std::format(
458 "basic_inplace_string::append: new_size (which is {}) > max_size (which is {})",
new_size,
max_size())};
460 traits_type::copy(
end(),
str.data(),
str.size());
468 template <std::
size_t N2>
472 throw std::length_error{std::format(
473 "basic_inplace_string::operator+=: new_size (which is {}) > max_size (which is {})",
new_size,
max_size())};
475 traits_type::copy(
end(),
str.data(),
str.size());
485 throw std::length_error{
486 std::format(
"basic_inplace_string::resize: count (which is {}) > max_size (which is {})",
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())};
518 template <std::
size_t N2>
528 constexpr auto find(std::basic_string_view<value_type, traits_type>
str,
561 template <std::
size_t N2>
571 constexpr auto rfind(std::basic_string_view<value_type, traits_type>
str,
606 template <std::
size_t N2>
634 template <std::
size_t N2>
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());
651 return std::ranges::equal(
lhs.begin(),
lhs.end(),
rhs.begin());
659 std::basic_string_view<value_type, traits_type>
rhs)
noexcept ->
bool {
660 return std::ranges::equal(
lhs.begin(),
lhs.end(),
rhs.begin());
667 friend constexpr auto operator==(std::basic_string_view<value_type, traits_type>
lhs,
677 return traits_type::compare(
lhs.data(),
rhs, traits_type::length(
rhs)) == 0;
701 std::basic_string_view<value_type, traits_type>
rhs)
noexcept ->
bool {
709 friend constexpr auto operator!=(std::basic_string_view<value_type, traits_type>
lhs,
734 friend inline auto operator<<(std::basic_ostream<value_type, traits_type>& ostream,
736 return ostream <<
rhs.view();
743 friend inline auto operator>>(std::basic_istream<value_type, traits_type>& istream,
745 const auto new_size =
rhs.size() + istream.rdbuf()->in_avail();
747 throw std::length_error{
748 std::format(
"basic_inplace_string::operator>>: new_size (which is {}) > max_size (which is {})",
new_size,
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());
760template <
typename CharT, std::
size_t N>
765template <std::
size_t N>
769template <std::
size_t N>
773template <std::
size_t N>
777template <std::
size_t N>
785template <std::
size_t N,
class CharT,
class Traits>
789 [[nodiscard]]
auto inline operator()(const ::gw::basic_inplace_string<N, CharT, Traits>& str)
const noexcept
791 return hash<basic_string_view<CharT, Traits>>{}(
static_cast<basic_string_view<CharT, Traits>
>(str));
796template <std::
size_t N,
class CharT,
class Traits>
800 template <
class ParseContext>
801 constexpr auto parse(ParseContext& context)
const -> ParseContext::iterator {
802 return context.begin();
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;
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
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