51 :
private generic_ordering_from_three_way_compare<string_view>
52 ,
private string_view_ostream_mixin<string_view> {
54 using character = detail::character;
56 using raw_c_string = detail::raw_c_string;
58 using const_char_span = span<character
const>;
61 using integral_comparison_result =
int;
67 static constexpr std::size_t npos{std::numeric_limits<std::size_t>::max()};
73 using element_type = const_char_span::element_type;
76 using value_type = const_char_span::value_type;
79 using size_type = std::size_t;
81 using difference_type = std::ptrdiff_t;
83 using pointer = const_char_span::pointer;
85 using const_pointer = const_char_span::const_pointer;
87 using reference = const_char_span::reference;
89 using const_reference = const_char_span::const_reference;
91 using iterator = const_char_span::iterator;
93 using const_iterator = const_char_span::const_iterator;
95 using reverse_iterator = const_char_span::reverse_iterator;
97 using const_reverse_iterator = const_char_span::const_reverse_iterator;
105 constexpr string_view()
noexcept =
default;
116 constexpr string_view(raw_c_string
const str, std::size_t
const str_length)
noexcept
117 : generic_ordering_from_three_way_compare<string_view>(),
118 str_span_(str, str_length) {}
125 template <std::size_t N>
127 inline constexpr string_view(character
const (&literal)[N])
noexcept
128 : string_view(literal, N - 1) {}
139 constexpr string_view(raw_c_string
const null_terminated_string)
noexcept
140 : string_view(null_terminated_string, detail::string_length(null_terminated_string)) {}
154 template <
typename String, constraints<std::enable_if_t<std::is_same<String, std::string>::value>> =
nullptr>
156 string_view(String
const& str)
noexcept
157 : string_view(str.data(), str.size()) {}
161 constexpr string_view(string_view
const& other)
noexcept =
default;
164 constexpr string_view(string_view&& other)
noexcept =
default;
167 ~string_view() =
default;
172 constexpr auto begin()
const noexcept -> const_iterator {
return str_span_.begin(); }
177 constexpr auto end()
const noexcept -> const_iterator {
return str_span_.end(); }
182 constexpr auto cbegin()
const noexcept -> const_iterator {
return begin(); }
187 constexpr auto cend()
const noexcept -> const_iterator {
return end(); }
192 constexpr auto rbegin()
const noexcept -> reverse_iterator {
return str_span_.rbegin(); }
197 constexpr auto rend()
const noexcept -> reverse_iterator {
return str_span_.rend(); }
202 constexpr auto crbegin()
const noexcept -> const_reverse_iterator {
return str_span_.rbegin(); }
207 constexpr auto crend()
const noexcept -> const_reverse_iterator {
return str_span_.rend(); }
212 constexpr auto size()
const noexcept -> size_type {
return str_span_.size(); }
217 constexpr auto length()
const noexcept -> size_type {
return str_span_.size(); }
223 constexpr auto empty()
const noexcept ->
bool {
return size() == 0U; }
227 static constexpr auto max_size()
noexcept -> size_type {
return std::numeric_limits<string_view::size_type>::max(); }
242 constexpr auto compare(string_view
const other)
const noexcept -> integral_comparison_result {
243 return from_strong_ordering(three_way_compare(*
this, other));
254 constexpr auto compare(size_type
const pos1, size_type
const length1, string_view
const other)
const noexcept
255 -> integral_comparison_result {
256 return substr(pos1, length1).compare(other);
269 constexpr auto compare(
270 size_type
const pos1,
271 size_type
const length1,
272 string_view
const other,
273 size_type
const pos2,
274 size_type
const length2
275 )
const noexcept -> integral_comparison_result {
276 return substr(pos1, length1).compare(other.substr(pos2, length2));
285 constexpr auto compare(raw_c_string
const other)
const noexcept -> integral_comparison_result {
286 return from_strong_ordering(detail::lexicographic_string_compare(str_span_, other));
297 constexpr auto compare(size_type
const pos1, size_type
const length1, raw_c_string
const other)
const noexcept
298 -> integral_comparison_result {
299 return substr(pos1, length1).compare(other);
312 constexpr auto compare(
313 size_type
const pos1,
314 size_type
const length1,
315 raw_c_string
const other,
316 size_type
const length2
317 )
const noexcept -> integral_comparison_result {
318 return substr(pos1, length1).compare(string_view{other, length2});
324 constexpr auto substr()
const noexcept -> string_view {
return *
this; }
335 constexpr auto substr(size_type
const pos, size_type
const count = npos)
const noexcept -> string_view {
337 size_type
const bounded_pos{std::min(pos, size())};
338 size_type
const bounded_size{std::min((size() - bounded_pos), count)};
339 return {arene::base::next(data(),
static_cast<std::ptrdiff_t>(bounded_pos)), bounded_size};
348 constexpr void swap(string_view& other)
noexcept { ::arene::base::swap(str_span_, other.str_span_); }
354 constexpr auto data()
const noexcept -> const_pointer {
return str_span_.data(); }
360 constexpr auto operator=(string_view
const& other)
noexcept -> string_view& =
default;
366 constexpr auto operator=(string_view&& other)
noexcept -> string_view& =
default;
373 constexpr auto operator[](std::size_t pos)
const noexcept -> const_reference {
374 ARENE_PRECONDITION(pos < size());
375 return str_span_[pos];
383 constexpr auto copy(character*
const dest, size_type
const n)
const noexcept -> size_type {
384 return copy(dest, n, 0U);
394 constexpr auto copy(character*
const dest, size_type
const n, size_type
const pos)
const noexcept -> size_type {
395 auto const sub = substr(pos, n);
396 auto const target = span<character>{dest, sub.length()};
397 std::ignore = ::arene::base::copy(sub.begin(), sub.end(), target.begin());
406 constexpr auto front()
const noexcept -> const_reference {
407 ARENE_PRECONDITION(!empty());
408 return str_span_.front();
416 constexpr auto back()
const noexcept -> const_reference {
417 ARENE_PRECONDITION(!empty());
418 return str_span_.back();
426 constexpr void remove_prefix(size_type
const count)
noexcept { *
this = substr(count); }
435 constexpr void remove_suffix(size_type
const count)
noexcept { *
this = substr(0U, size() - std::min(count, size())); }
443 constexpr auto starts_with(string_view
const other)
const noexcept ->
bool {
444 return substr(0U, other.size()) == other;
454 constexpr auto starts_with(raw_c_string
const other)
const noexcept ->
bool {
455 return starts_with(string_view{other});
463 constexpr auto starts_with(character
const chr)
const noexcept ->
bool {
return (!empty()) && (front() == chr); }
470 constexpr auto ends_with(string_view
const other)
const noexcept ->
bool {
471 return (other.size() <= size()) && substr(size() - other.size(), other.size()) == other;
481 constexpr auto ends_with(raw_c_string
const other)
const noexcept ->
bool {
return ends_with(string_view{other}); }
487 constexpr auto ends_with(character
const chr)
const noexcept ->
bool {
return (!empty()) && (back() == chr); }
495 constexpr auto find(string_view
const str, size_type
const pos = 0U)
const noexcept -> size_type {
500 for (size_type index{pos}; (size() - index) >= str.size(); ++index) {
501 if (substr(index, str.size()) == str) {
516 constexpr auto find(raw_c_string
const str, size_type
const pos = 0U)
const noexcept -> size_type {
517 return find(string_view{str}, pos);
529 constexpr auto find(raw_c_string
const str, size_type
const pos, size_type
const n)
const noexcept -> size_type {
530 return find(string_view{str, n}, pos);
539 constexpr auto find(character
const chr, size_type
const pos = 0U)
const noexcept -> size_type {
540 difference_type
const offset{
static_cast<difference_type>(std::min(pos, size()))};
541 auto const location = ::arene::base::find(begin() + offset, end(), chr);
542 return location == end() ? npos :
static_cast<size_type>(location - begin());
552 constexpr auto rfind(string_view
const str, size_type
const pos = npos)
const noexcept -> size_type {
554 for (size_type index{pos > size() ? size() : pos}; index <= size(); --index) {
555 if (substr(index, str.size()) == str) {
571 constexpr auto rfind(raw_c_string
const str, size_type
const pos = npos)
const noexcept -> size_type {
572 return rfind(string_view{str}, pos);
585 constexpr auto rfind(raw_c_string
const str, size_type
const pos, size_type
const n)
const noexcept -> size_type {
586 return rfind(string_view{str, n}, pos);
596 constexpr auto rfind(character
const chr, size_type
const pos = npos)
const noexcept -> size_type {
597 auto start = rbegin();
602 start +=
static_cast<difference_type>(size() - pos);
604 auto const location = ::arene::base::find(start, rend(), chr);
605 return location == rend() ? npos :
static_cast<size_type>(rend() - location - 1);
619 constexpr auto find_first_of(string_view
const str, size_type
const pos = 0U)
const noexcept -> size_type {
624 for (size_type index{pos}; index < size(); ++index) {
625 if (str.find(str_span_[index]) != npos) {
642 constexpr auto find_first_of(raw_c_string
const str, size_type
const pos = 0U)
const noexcept -> size_type {
643 return find_first_of(string_view{str}, pos);
654 constexpr auto find_first_of(raw_c_string
const str, size_type
const pos, size_type
const n)
const noexcept
656 return find_first_of(string_view{str, n}, pos);
664 constexpr auto find_first_of(character
const chr, size_type
const pos = 0U)
const noexcept -> size_type {
665 return find(chr, pos);
675 constexpr auto find_first_not_of(string_view
const str, size_type
const pos = 0U)
const noexcept -> size_type {
677 return pos < size() ? pos : npos;
680 for (size_type index{pos}; index < size(); ++index) {
681 if (str.find(str_span_[index]) == npos) {
697 constexpr auto find_first_not_of(raw_c_string
const str, size_type
const pos = 0U)
const noexcept -> size_type {
698 return find_first_not_of(string_view{str}, pos);
709 constexpr auto find_first_not_of(raw_c_string
const str, size_type
const pos, size_type
const n)
const noexcept
711 return find_first_not_of(string_view{str, n}, pos);
719 constexpr auto find_first_not_of(character
const chr, size_type
const pos = 0U)
const noexcept -> size_type {
720 return find_first_not_of(string_view{&chr, 1U}, pos);
731 constexpr auto find_last_of(string_view
const str, size_type
const pos = npos)
const noexcept -> size_type {
736 for (size_type index{pos >= size() ? size() - 1U : pos}; index < size(); --index) {
737 if (str.find(str_span_[index]) != npos) {
754 constexpr auto find_last_of(raw_c_string
const str, size_type
const pos = npos)
const noexcept -> size_type {
755 return find_last_of(string_view{str}, pos);
768 constexpr auto find_last_of(raw_c_string
const str, size_type
const pos, size_type
const n)
const noexcept
770 return find_last_of(string_view{str, n}, pos);
779 constexpr auto find_last_of(character
const chr, size_type
const pos = npos)
const noexcept -> size_type {
780 return rfind(chr, pos);
791 constexpr auto find_last_not_of(string_view
const str, size_type
const pos = npos)
const noexcept -> size_type {
793 return pos < size() ? pos : size() - 1U;
796 for (size_type index{pos >= size() ? size() - 1U : pos}; index < size(); --index) {
797 if (str.find(str_span_[index]) == npos) {
814 constexpr auto find_last_not_of(raw_c_string
const str, size_type
const pos = npos)
const noexcept -> size_type {
815 return find_last_not_of(string_view{str}, pos);
827 constexpr auto find_last_not_of(raw_c_string
const str, size_type
const pos, size_type
const n)
const noexcept
829 return find_last_not_of(string_view{str, n}, pos);
838 constexpr auto find_last_not_of(character
const chr, size_type
const pos = npos)
const noexcept -> size_type {
839 return find_last_not_of(string_view{&chr, 1U}, pos);
858 static constexpr auto three_way_compare(string_view
const lhs, string_view
const rhs)
noexcept -> strong_ordering {
859 return detail::lexicographic_string_compare(lhs.str_span_, rhs.str_span_);
867 operator std::string()
const;
877 static constexpr auto fast_inequality_check(string_view
const first, string_view
const second)
noexcept
878 -> inequality_heuristic {
879 return (first.size() == second.size()) ? inequality_heuristic::may_be_equal_or_not_equal
880 : inequality_heuristic::definitely_not_equal;
886 const_char_span str_span_;
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10