2 * Copyright 2017 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 // @author: Eric Niebler (eniebler)
18 // Fixed-size string type, for constexpr string handling.
24 #include <initializer_list>
28 #include <type_traits>
31 #include <folly/ConstexprMath.h>
32 #include <folly/Portability.h>
33 #include <folly/Range.h>
34 #include <folly/Utility.h>
35 #include <folly/portability/BitsFunctexcept.h>
36 #include <folly/portability/Constexpr.h>
40 template <class Char, std::size_t N>
41 class BasicFixedString;
43 template <std::size_t N>
44 using FixedString = BasicFixedString<char, N>;
47 namespace fixedstring {
49 // This is a template so that the class static npos can be defined in the
51 template <class = void>
52 struct FixedStringBase_ {
53 static constexpr std::size_t npos = static_cast<std::size_t>(-1);
57 constexpr std::size_t FixedStringBase_<Void>::npos;
59 using FixedStringBase = FixedStringBase_<>;
61 // Intentionally NOT constexpr. By making this not constexpr, we make
62 // checkOverflow below ill-formed in a constexpr context when the condition
63 // it's testing for fails. In this way, precondition violations are reported
64 // at compile-time instead of at runtime.
65 [[noreturn]] inline void assertOutOfBounds() {
66 assert(false && "Array index out of bounds in BasicFixedString");
67 std::__throw_out_of_range("Array index out of bounds in BasicFixedString");
70 constexpr std::size_t checkOverflow(std::size_t i, std::size_t max) {
71 return i <= max ? i : (assertOutOfBounds(), max);
74 constexpr std::size_t checkOverflowOrNpos(std::size_t i, std::size_t max) {
75 return i == FixedStringBase::npos
77 : (i <= max ? i : (assertOutOfBounds(), max));
80 // Intentionally NOT constexpr. See note above for assertOutOfBounds
81 [[noreturn]] inline void assertNotNullTerminated() noexcept {
84 "Non-null terminated string used to initialize a BasicFixedString");
85 std::terminate(); // Fail hard, fail fast.
88 // Parsing help for human readers: the following is a constexpr noexcept
89 // function that accepts a reference to an array as a parameter and returns
90 // a reference to the same array.
91 template <class Char, std::size_t N>
92 constexpr const Char (&checkNullTerminated(const Char (&a)[N]) noexcept)[N] {
93 // Strange decltype(a)(a) used to make MSVC happy.
94 return a[N - 1u] == Char(0)
96 // In Debug mode, guard against embedded nulls:
97 && N - 1u == folly::detail::constexpr_strlen_internal(a, 0u)
100 : (assertNotNullTerminated(), decltype(a)(a));
103 enum class Cmp : int { LT = -1, EQ = 0, GT = 1 };
105 // Rather annoyingly, GCC's -Warray-bounds warning issues false positives for
106 // this code. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61971
107 #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 5
108 #pragma GCC diagnostic push
109 #pragma GCC diagnostic ignored "-Warray-bounds"
112 template <class Left, class Right>
113 constexpr Cmp compare_(
115 std::size_t left_pos,
116 std::size_t left_size,
118 std::size_t right_pos,
119 std::size_t right_size) noexcept {
120 return left_pos == left_size
121 ? (right_pos == right_size ? Cmp::EQ : Cmp::LT)
122 : (right_pos == right_size ? Cmp::GT
123 : (left[left_pos] < right[right_pos]
125 : (left[left_pos] > right[right_pos]
127 : fixedstring::compare_(
136 template <class Left, class Right>
137 constexpr bool equal_(
139 std::size_t left_size,
141 std::size_t right_size) noexcept {
142 return left_size == right_size &&
143 Cmp::EQ == compare_(left, 0u, left_size, right, 0u, right_size);
146 template <class Char, class Left, class Right>
147 constexpr Char char_at_(
149 std::size_t left_count,
151 std::size_t right_count,
152 std::size_t i) noexcept {
153 return i < left_count
155 : i < (left_count + right_count) ? right[i - left_count] : Char(0);
158 template <class Char, class Left, class Right>
159 constexpr Char char_at_(
161 std::size_t left_size,
162 std::size_t left_pos,
163 std::size_t left_count,
165 std::size_t right_pos,
166 std::size_t right_count,
167 std::size_t i) noexcept {
170 : (i < right_count + left_pos ? right[i - left_pos + right_pos]
171 : (i < left_size - left_count + right_count
172 ? left[i - right_count + left_count]
176 template <class Left, class Right>
177 constexpr bool find_at_(
181 std::size_t count) noexcept {
182 return 0u == count || (left[pos + count - 1u] == right[count - 1u] &&
183 find_at_(left, right, pos, count - 1u));
186 template <class Char, class Right>
188 find_one_of_at_(Char ch, const Right& right, std::size_t pos) noexcept {
190 (ch == right[pos - 1u] || find_one_of_at_(ch, right, pos - 1u));
193 template <class Left, class Right>
194 constexpr std::size_t find_(
196 std::size_t left_size,
199 std::size_t count) noexcept {
200 return find_at_(left, right, pos, count) ? pos
201 : left_size <= pos + count
202 ? FixedStringBase::npos
203 : find_(left, left_size, right, pos + 1u, count);
206 template <class Left, class Right>
207 constexpr std::size_t rfind_(
211 std::size_t count) noexcept {
212 return find_at_(left, right, pos, count)
214 : 0u == pos ? FixedStringBase::npos
215 : rfind_(left, right, pos - 1u, count);
218 template <class Left, class Right>
219 constexpr std::size_t find_first_of_(
221 std::size_t left_size,
224 std::size_t count) noexcept {
225 return find_one_of_at_(left[pos], right, count) ? pos
226 : left_size <= pos + 1u
227 ? FixedStringBase::npos
228 : find_first_of_(left, left_size, right, pos + 1u, count);
231 template <class Left, class Right>
232 constexpr std::size_t find_first_not_of_(
234 std::size_t left_size,
237 std::size_t count) noexcept {
238 return !find_one_of_at_(left[pos], right, count) ? pos
239 : left_size <= pos + 1u
240 ? FixedStringBase::npos
241 : find_first_not_of_(left, left_size, right, pos + 1u, count);
244 template <class Left, class Right>
245 constexpr std::size_t find_last_of_(
249 std::size_t count) noexcept {
250 return find_one_of_at_(left[pos], right, count)
252 : 0u == pos ? FixedStringBase::npos
253 : find_last_of_(left, right, pos - 1u, count);
256 template <class Left, class Right>
257 constexpr std::size_t find_last_not_of_(
261 std::size_t count) noexcept {
262 return !find_one_of_at_(left[pos], right, count)
264 : 0u == pos ? FixedStringBase::npos
265 : find_last_not_of_(left, right, pos - 1u, count);
269 template <class Char, class Left, class Right, std::size_t... Is>
270 static constexpr BasicFixedString<Char, sizeof...(Is)> concat_(
272 std::size_t left_count,
274 std::size_t right_count,
275 folly::index_sequence<Is...> is) noexcept {
276 return {left, left_count, right, right_count, is};
279 template <class Char, class Left, class Right, std::size_t... Is>
280 static constexpr BasicFixedString<Char, sizeof...(Is)> replace_(
282 std::size_t left_size,
283 std::size_t left_pos,
284 std::size_t left_count,
286 std::size_t right_pos,
287 std::size_t right_count,
288 folly::index_sequence<Is...> is) noexcept {
299 template <class Char, std::size_t N>
300 static constexpr const Char (
301 &data_(const BasicFixedString<Char, N>& that) noexcept)[N + 1u] {
306 #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 4
307 #pragma GCC diagnostic pop
311 FOLLY_CPP14_CONSTEXPR void constexpr_swap(T& a, T& b) noexcept(
312 noexcept(a = T(std::move(a)))) {
313 T tmp((std::move(a)));
318 // For constexpr reverse iteration over a BasicFixedString
320 struct ReverseIterator {
326 using other = typename std::conditional<
327 std::is_const<T>::value,
328 ReverseIterator<typename std::remove_const<T>::type>,
332 using value_type = typename std::remove_const<T>::type;
333 using reference = T&;
335 using difference_type = std::ptrdiff_t;
336 using iterator_category = std::random_access_iterator_tag;
338 constexpr ReverseIterator() = default;
339 constexpr ReverseIterator(const ReverseIterator&) = default;
340 FOLLY_CPP14_CONSTEXPR ReverseIterator& operator=(const ReverseIterator&) =
342 constexpr explicit ReverseIterator(T* p) noexcept : p_(p) {}
343 constexpr /* implicit */ ReverseIterator(const other& that) noexcept
345 friend constexpr bool operator==(
347 ReverseIterator b) noexcept {
350 friend constexpr bool operator!=(
352 ReverseIterator b) noexcept {
355 constexpr reference operator*() const {
358 FOLLY_CPP14_CONSTEXPR ReverseIterator& operator++() noexcept {
362 FOLLY_CPP14_CONSTEXPR ReverseIterator operator++(int)noexcept {
367 FOLLY_CPP14_CONSTEXPR ReverseIterator& operator--() noexcept {
371 FOLLY_CPP14_CONSTEXPR ReverseIterator operator--(int)noexcept {
376 FOLLY_CPP14_CONSTEXPR ReverseIterator& operator+=(std::ptrdiff_t i) noexcept {
380 friend constexpr ReverseIterator operator+(
382 ReverseIterator that) noexcept {
383 return ReverseIterator{that.p_ - i};
385 friend constexpr ReverseIterator operator+(
386 ReverseIterator that,
387 std::ptrdiff_t i) noexcept {
388 return ReverseIterator{that.p_ - i};
390 FOLLY_CPP14_CONSTEXPR ReverseIterator& operator-=(std::ptrdiff_t i) noexcept {
394 friend constexpr ReverseIterator operator-(
395 ReverseIterator that,
396 std::ptrdiff_t i) noexcept {
397 return ReverseIterator{that.p_ + i};
399 friend constexpr std::ptrdiff_t operator-(
401 ReverseIterator b) noexcept {
404 constexpr reference operator[](std::ptrdiff_t i) const noexcept {
409 } // namespace fixedstring
410 } // namespace detail
412 // Defined in folly/Hash.h
413 std::uint32_t hsieh_hash32_buf(const void* buf, std::size_t len);
415 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** *
416 * \class BasicFixedString
418 * \tparam Char The character type. Must be a scalar type.
419 * \tparam N The capacity and max size of string instances of this type.
421 * \brief A class for holding up to `N` characters of type `Char` that is
422 * amenable to `constexpr` string manipulation. It is guaranteed to not
423 * perform any dynamic allocation.
425 * `BasicFixedString` is a `std::string` work-alike that stores characters in an
426 * internal buffer. It has minor interface differences that make it easy to work
427 * with strings in a `constexpr` context.
432 * constexpr auto hello = makeFixedString("hello"); // a FixedString<5>
433 * constexpr auto world = makeFixedString("world"); // a FixedString<5>
434 * constexpr auto hello_world = hello + ' ' + world + '!'; // a FixedString<12>
435 * static_assert(hello_world == "hello world!", "neato!");
438 * `FixedString<N>` is an alias for `BasicFixedString<char, N>`.
440 * \par Constexpr and In-place Mutation
442 * On a C++14 compiler, `BasicFixedString` supports the full `std::string`
443 * interface as `constexpr` member functions. On a C++11 compiler, the mutating
444 * members are not `constexpr`, but non-mutating alternatives, which create a
445 * new string, can be used instead. For example, instead of this:
448 * constexpr FixedString<10> replace_example_cpp14() {
449 * FixedString<10> test{"****"};
450 * test.replace(1, 2, "!!!!");
451 * return test; // returns "*!!!!*"
455 * You might write this instead:
458 * constexpr FixedString<10> replace_example_cpp11() {
459 * // GNU compilers have an extension that make it possible to create
460 * // FixedString objects with a `""_fs` user-defined literal.
461 * using namespace folly;
462 * return makeFixedString("****").creplace(1, 2, "!!!!"); // "*!!!!*"
466 * \par User-defined Literals
467 * Instead of using the `folly::makeFixedString` helper function, you can use
468 * a user-defined literal to make `FixedString` instances. The UDL feature of
469 * C++ has some limitations that make this less than ideal; you must tell the
470 * compiler roughly how many characters are in the string. The suffixes `_fs4`,
471 * `_fs8`, `_fs16`, `_fs32`, `_fs64`, and `_fs128` exist to create instances
472 * of types `FixedString<4>`, `FixedString<8>`, etc. For example:
475 * using namespace folly::string_literals;
476 * constexpr auto hello = "hello"_fs8; // A FixedString<8> containing "hello"
479 * See Error Handling below for what to expect when you try to exceed the
480 * capacity of a `FixedString` by storing too many characters in it.
482 * If your compiler supports GNU extensions, there is one additional suffix you
483 * can use: `_fs`. This suffix always creates `FixedString` objects of exactly
484 * the right size. For example:
487 * using namespace folly::string_literals;
488 * // NOTE: Only works on compilers with GNU extensions enabled. Clang and
489 * // gcc support this (-Wgnu-string-literal-operator-template):
490 * constexpr auto hello = "hello"_fs; // A FixedString<5> containing "hello"
493 * \par Error Handling:
494 * The capacity of a `BasicFixedString` is set at compile time. When the user
495 * asks the string to exceed its capacity, one of three things will happen,
496 * depending on the context:
498 * -# If the attempt is made while evaluating a constant expression, the
499 * program will fail to compile.
500 * -# Otherwise, if the program is being run in debug mode, it will `assert`.
501 * -# Otherwise, the failed operation will throw a `std::out_of_range`
504 * This is also the case if an invalid offset is passed to any member function,
505 * or if `pop_back` or `cpop_back` is called on an empty `BasicFixedString`.
507 * Member functions documented as having preconditions will assert in Debug
508 * mode (`!defined(NDEBUG)`) on precondition failures. Those documented with
509 * \b Throws clauses will throw the specified exception on failure. Those with
510 * both a precondition and a \b Throws clause will assert in Debug and throw
513 template <class Char, std::size_t N>
514 class BasicFixedString : private detail::fixedstring::FixedStringBase {
516 template <class, std::size_t>
517 friend class BasicFixedString;
518 friend struct detail::fixedstring::Helper;
520 // FUTURE: use constexpr_log2 to fold instantiations of BasicFixedString
521 // together. All BasicFixedString<C, N> instantiations could share the
522 // implementation of BasicFixedString<C, M>, where M is the next highest power
525 // Also, because of alignment of the data_ and size_ members, N should never
526 // be smaller than `(alignof(std::size_t)/sizeof(C))-1` (-1 because of the
527 // null terminator). OR, create a specialization for BasicFixedString<C, 0u>
528 // that does not have a size_ member, since it is unnecessary.
529 Char data_[N + 1u]; // +1 for the null terminator
530 std::size_t size_; // Nbr of chars, not incl. null terminator. size_ <= N.
532 using Indices = folly::make_index_sequence<N>;
534 template <class That, std::size_t... Is>
535 constexpr BasicFixedString(
538 folly::index_sequence<Is...>,
540 std::size_t count = npos) noexcept
541 : data_{(Is < (size - pos) && Is < count ? that[Is + pos] : Char(0))...,
543 size_{folly::constexpr_min(size - pos, count)} {}
545 template <std::size_t... Is>
546 constexpr BasicFixedString(
549 folly::index_sequence<Is...>) noexcept
550 : data_{((Is < count) ? ch : Char(0))..., Char(0)}, size_{count} {}
552 // Concatenation constructor
553 template <class Left, class Right, std::size_t... Is>
554 constexpr BasicFixedString(
556 std::size_t left_size,
558 std::size_t right_size,
559 folly::index_sequence<Is...>) noexcept
560 : data_{detail::fixedstring::char_at_<Char>(
567 size_{left_size + right_size} {}
569 // Replace constructor
570 template <class Left, class Right, std::size_t... Is>
571 constexpr BasicFixedString(
573 std::size_t left_size,
574 std::size_t left_pos,
575 std::size_t left_count,
577 std::size_t right_pos,
578 std::size_t right_count,
579 folly::index_sequence<Is...>) noexcept
580 : data_{detail::fixedstring::char_at_<Char>(
590 size_{left_size - left_count + right_count} {}
593 using size_type = std::size_t;
594 using difference_type = std::ptrdiff_t;
595 using reference = Char&;
596 using const_reference = const Char&;
597 using pointer = Char*;
598 using const_pointer = const Char*;
599 using iterator = Char*;
600 using const_iterator = const Char*;
601 using reverse_iterator = detail::fixedstring::ReverseIterator<Char>;
602 using const_reverse_iterator =
603 detail::fixedstring::ReverseIterator<const Char>;
605 using detail::fixedstring::FixedStringBase::npos;
607 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
609 * \post `size() == 0`
610 * \post `at(0) == Char(0)`
612 constexpr BasicFixedString() : data_{}, size_{} {}
614 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
616 * \post `size() == that.size()`
617 * \post `0 == strncmp(data(), that.data(), size())`
618 * \post `at(size()) == Char(0)`
620 constexpr BasicFixedString(const BasicFixedString& /*that*/) = default;
622 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
623 * Construct from a differently-sized BasicFixedString
624 * \pre `that.size() <= N`
625 * \post `size() == that.size()`
626 * \post `0 == strncmp(data(), that.data(), size())`
627 * \post `at(size()) == Char(0)`
628 * \throw std::out_of_range when that.size() > N. When M <= N, this
629 * constructor will never throw.
630 * \note Conversions from larger-capacity BasicFixedString objects to smaller
631 * ones (`M > N`) are allowed as long as the *size()* of the source string
634 template <std::size_t M>
635 constexpr /* implicit */ BasicFixedString(
636 const BasicFixedString<Char, M>& that) noexcept(M <= N)
637 : BasicFixedString{that, 0u, that.size_} {}
639 // Why is this deleted? To avoid confusion with the constructor that takes
640 // a const Char* and a count.
641 template <std::size_t M>
642 constexpr BasicFixedString(
643 const BasicFixedString<Char, M>& that,
644 std::size_t pos) noexcept(false) = delete;
646 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
647 * Construct from an BasicFixedString, an offset, and a count
648 * \param that The source string
649 * \param pos The starting position in `that`
650 * \param count The number of characters to copy. If `npos`, `count` is taken
651 * to be `that.size()-pos`.
652 * \pre `pos <= that.size()`
653 * \pre `count <= that.size()-pos && count <= N`
654 * \post `size() == count`
655 * \post `0 == strncmp(data(), that.data()+pos, size())`
656 * \post `at(size()) == Char(0)`
657 * \throw std::out_of_range when pos+count > that.size(), or when
660 template <std::size_t M>
661 constexpr BasicFixedString(
662 const BasicFixedString<Char, M>& that,
664 std::size_t count) noexcept(false)
668 folly::make_index_sequence<(M < N ? M : N)>{},
670 detail::fixedstring::checkOverflow(
671 detail::fixedstring::checkOverflowOrNpos(
674 detail::fixedstring::checkOverflow(pos, that.size_)),
677 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
678 * Construct from a string literal
680 * \pre `that[M-1] == Char(0)`
681 * \post `0 == strncmp(data(), that, M-1)`
682 * \post `size() == M-1`
683 * \post `at(size()) == Char(0)`
685 template <std::size_t M, class = typename std::enable_if<(M - 1u <= N)>::type>
686 constexpr /* implicit */ BasicFixedString(const Char (&that)[M]) noexcept
687 : BasicFixedString{detail::fixedstring::checkNullTerminated(that),
689 folly::make_index_sequence<M - 1u>{}} {}
691 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
692 * Construct from a `const Char*` and count
693 * \pre `that` points to an array of at least `count` characters.
695 * \post `size() == count`
696 * \post `0 == strncmp(data(), that, size())`
697 * \post `at(size()) == Char(0)`
698 * \throw std::out_of_range when count > N
700 constexpr BasicFixedString(const Char* that, std::size_t count) noexcept(
702 : BasicFixedString{that,
703 detail::fixedstring::checkOverflow(count, N),
706 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
707 * Construct an BasicFixedString that contains `count` characters, all
710 * \post `size() == count`
711 * \post `npos == find_first_not_of(ch)`
712 * \post `at(size()) == Char(0)`
713 * \throw std::out_of_range when count > N
715 constexpr BasicFixedString(std::size_t count, Char ch) noexcept(false)
716 : BasicFixedString{detail::fixedstring::checkOverflow(count, N),
720 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
721 * Construct an BasicFixedString from a `std::initializer_list` of
723 * \pre `il.size() <= N`
724 * \post `size() == count`
725 * \post `0 == strncmp(data(), il.begin(), size())`
726 * \post `at(size()) == Char(0)`
727 * \throw std::out_of_range when il.size() > N
729 constexpr BasicFixedString(std::initializer_list<Char> il) noexcept(false)
730 : BasicFixedString{il.begin(), il.size()} {}
732 FOLLY_CPP14_CONSTEXPR BasicFixedString& operator=(
733 const BasicFixedString&) noexcept = default;
735 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
736 * Assign from a `BasicFixedString<Char, M>`.
737 * \pre `that.size() <= N`
738 * \post `size() == that.size()`
739 * \post `0 == strncmp(data(), that.begin(), size())`
740 * \post `at(size()) == Char(0)`
741 * \throw std::out_of_range when that.size() > N. When M <= N, this
742 * assignment operator will never throw.
743 * \note Assignments from larger-capacity BasicFixedString objects to smaller
744 * ones (`M > N`) are allowed as long as the *size* of the source string is
748 template <std::size_t M>
749 FOLLY_CPP14_CONSTEXPR BasicFixedString& operator=(
750 const BasicFixedString<Char, M>& that) noexcept(M <= N) {
751 detail::fixedstring::checkOverflow(that.size_, N);
752 size_ = that.copy(data_, that.size_);
753 data_[size_] = Char(0);
757 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
758 * Assign from a null-terminated array of characters.
760 * \pre `that` has no embedded null characters
761 * \pre `that[M-1]==Char(0)`
762 * \post `size() == M-1`
763 * \post `0 == strncmp(data(), that, size())`
764 * \post `at(size()) == Char(0)`
767 template <std::size_t M, class = typename std::enable_if<(M - 1u <= N)>::type>
768 FOLLY_CPP14_CONSTEXPR BasicFixedString& operator=(
769 const Char (&that)[M]) noexcept {
770 return assign(detail::fixedstring::checkNullTerminated(that), M - 1u);
773 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
774 * Assign from an `initializer_list` of characters.
775 * \pre `il.size() <= N`
776 * \post `size() == il.size()`
777 * \post `0 == strncmp(data(), il.begin(), size())`
778 * \post `at(size()) == Char(0)`
779 * \throw std::out_of_range when il.size() > N
782 FOLLY_CPP14_CONSTEXPR BasicFixedString& operator=(
783 std::initializer_list<Char> il) noexcept(false) {
784 detail::fixedstring::checkOverflow(il.size(), N);
785 for (std::size_t i = 0u; i < il.size(); ++i) {
786 data_[i] = il.begin()[i];
789 data_[size_] = Char(0);
793 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
794 * Conversion to folly::Range
795 * \return `Range<Iter>{begin(), end()}`
799 class = typename std::enable_if<
800 std::is_convertible<Char*, Iter>::value>::type>
801 FOLLY_CPP14_CONSTEXPR /* implicit */ operator Range<Iter>() noexcept {
802 return {begin(), end()};
810 class = typename std::enable_if<
811 std::is_convertible<const Char*, Iter>::value>::type>
812 constexpr /* implicit */ operator Range<Iter>() const noexcept {
813 return {begin(), end()};
816 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
817 * Conversion to folly::Range
818 * \return `Range<Char*>{begin(), end()}`
820 FOLLY_CPP14_CONSTEXPR Range<Char*> toRange() noexcept {
821 return {begin(), end()};
827 constexpr Range<const Char*> toRange() const noexcept {
828 return {begin(), end()};
831 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
832 * Conversion to std::basic_string<Char>
833 * \return `std::basic_string<Char>{begin(), end()}`
835 /* implicit */ operator std::basic_string<Char>() const noexcept(false) {
836 return std::basic_string<Char>{begin(), end()};
839 std::basic_string<Char> toStdString() const noexcept(false) {
840 return std::basic_string<Char>{begin(), end()};
843 // Think hard about whether this is a good idea. It's certainly better than
844 // an implicit conversion to `const Char*` since `delete "hi"_fs` will fail
845 // to compile. But it creates ambiguities when passing a FixedString to an
846 // API that has overloads for `const char*` and `folly::Range`, for instance.
847 // using ArrayType = Char[N];
848 // FOLLY_CPP14_CONSTEXPR /* implicit */ operator ArrayType&() noexcept {
852 // using ConstArrayType = const Char[N];
853 // constexpr /* implicit */ operator ConstArrayType&() const noexcept {
857 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
858 * Assigns a sequence of `count` characters of value `ch`.
859 * \param count The count of characters.
862 * \post `size() == count`
863 * \post `npos == find_first_not_of(ch)`
864 * \post `at(size()) == Char(0)`
865 * \throw std::out_of_range when count > N
868 FOLLY_CPP14_CONSTEXPR BasicFixedString& assign(
870 Char ch) noexcept(false) {
871 detail::fixedstring::checkOverflow(count, N);
872 for (std::size_t i = 0u; i < count; ++i) {
876 data_[size_] = Char(0);
880 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
881 * Assigns characters from an `BasicFixedString` to this object.
882 * \note Equivalent to `assign(that, 0, that.size())`
884 template <std::size_t M>
885 FOLLY_CPP14_CONSTEXPR BasicFixedString& assign(
886 const BasicFixedString<Char, M>& that) noexcept(M <= N) {
890 // Why is this overload deleted? So users aren't confused by the difference
891 // between str.assign("foo", N) and str.assign("foo"_fs, N). In the former,
892 // N is a count of characters. In the latter, it would be a position, which
893 // totally changes the meaning of the code.
894 template <std::size_t M>
895 FOLLY_CPP14_CONSTEXPR BasicFixedString& assign(
896 const BasicFixedString<Char, M>& that,
897 std::size_t pos) noexcept(false) = delete;
899 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
900 * Assigns `count` characters from an `BasicFixedString` to this object,
901 * starting at position `pos` in the source object.
902 * \param that The source string.
903 * \param pos The starting position in the source string.
904 * \param count The number of characters to copy. If `npos`, `count` is taken
905 * to be `that.size()-pos`.
906 * \pre `pos <= that.size()`
907 * \pre `count <= that.size()-pos`
909 * \post `size() == count`
910 * \post `0 == strncmp(data(), that.begin() + pos, count)`
911 * \post `at(size()) == Char(0)`
912 * \throw std::out_of_range when pos > that.size() or count > that.size()-pos
916 template <std::size_t M>
917 FOLLY_CPP14_CONSTEXPR BasicFixedString& assign(
918 const BasicFixedString<Char, M>& that,
920 std::size_t count) noexcept(false) {
921 detail::fixedstring::checkOverflow(pos, that.size_);
924 detail::fixedstring::checkOverflowOrNpos(count, that.size_ - pos));
927 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
928 * Assigns characters from an `BasicFixedString` to this object.
929 * \pre `that` contains no embedded nulls.
930 * \pre `that[M-1] == Char(0)`
931 * \note Equivalent to `assign(that, M - 1)`
933 template <std::size_t M, class = typename std::enable_if<(M - 1u <= N)>::type>
934 FOLLY_CPP14_CONSTEXPR BasicFixedString& assign(
935 const Char (&that)[M]) noexcept {
936 return assign(detail::fixedstring::checkNullTerminated(that), M - 1u);
939 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
940 * Assigns `count` characters from a range of characters to this object.
941 * \param that A pointer to a range of characters.
942 * \param count The number of characters to copy.
943 * \pre `that` points to at least `count` characters.
945 * \post `size() == count`
946 * \post `0 == strncmp(data(), that, count)`
947 * \post `at(size()) == Char(0)`
948 * \throw std::out_of_range when count > N
951 FOLLY_CPP14_CONSTEXPR BasicFixedString& assign(
953 std::size_t count) noexcept(false) {
954 detail::fixedstring::checkOverflow(count, N);
955 for (std::size_t i = 0u; i < count; ++i) {
959 data_[size_] = Char(0);
963 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
964 * Swap the contents of this string with `that`.
966 FOLLY_CPP14_CONSTEXPR void swap(BasicFixedString& that) noexcept {
967 // less-than-or-equal here to copy the null terminator:
968 for (std::size_t i = 0u; i <= folly::constexpr_max(size_, that.size_);
970 detail::fixedstring::constexpr_swap(data_[i], that.data_[i]);
972 detail::fixedstring::constexpr_swap(size_, that.size_);
975 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
976 * Return a pointer to a range of `size()+1` characters, the last of which
979 FOLLY_CPP14_CONSTEXPR Char* data() noexcept {
986 constexpr const Char* data() const noexcept {
990 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
993 constexpr const Char* c_str() const noexcept {
997 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1000 FOLLY_CPP14_CONSTEXPR Char* begin() noexcept {
1007 constexpr const Char* begin() const noexcept {
1011 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1014 constexpr const Char* cbegin() const noexcept {
1018 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1019 * \return `data() + size()`.
1021 FOLLY_CPP14_CONSTEXPR Char* end() noexcept {
1022 return data_ + size_;
1028 constexpr const Char* end() const noexcept {
1029 return data_ + size_;
1032 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1033 * \return `data() + size()`.
1035 constexpr const Char* cend() const noexcept {
1039 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1040 * Returns a reverse iterator to the first character of the reversed string.
1041 * It corresponds to the last + 1 character of the non-reversed string.
1043 FOLLY_CPP14_CONSTEXPR reverse_iterator rbegin() noexcept {
1044 return reverse_iterator{data_ + size_};
1050 constexpr const_reverse_iterator rbegin() const noexcept {
1051 return const_reverse_iterator{data_ + size_};
1055 * \note Equivalent to `rbegin()` on a const-qualified reference to `*this`.
1057 constexpr const_reverse_iterator crbegin() const noexcept {
1061 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1062 * Returns a reverse iterator to the last + 1 character of the reversed
1063 * string. It corresponds to the first character of the non-reversed string.
1065 FOLLY_CPP14_CONSTEXPR reverse_iterator rend() noexcept {
1066 return reverse_iterator{data_};
1072 constexpr const_reverse_iterator rend() const noexcept {
1073 return const_reverse_iterator{data_};
1077 * \note Equivalent to `rend()` on a const-qualified reference to `*this`.
1079 constexpr const_reverse_iterator crend() const noexcept {
1084 * \return The number of `Char` elements in the string.
1086 constexpr std::size_t size() const noexcept {
1091 * \return The number of `Char` elements in the string.
1093 constexpr std::size_t length() const noexcept {
1098 * \return True if and only if `size() == 0`.
1100 constexpr bool empty() const noexcept {
1107 static constexpr std::size_t capacity() noexcept {
1114 static constexpr std::size_t max_size() noexcept {
1118 // We would need to reimplement folly::Hash to make this
1120 std::uint32_t hash() const noexcept {
1121 return folly::hsieh_hash32_buf(data_, size_);
1125 * \note `at(size())` is allowed will return `Char(0)`.
1126 * \return `*(data() + i)`
1127 * \throw std::out_of_range when i > size()
1129 FOLLY_CPP14_CONSTEXPR Char& at(std::size_t i) noexcept(false) {
1132 : (std::__throw_out_of_range("Out of range in BasicFixedString::at"),
1139 constexpr const Char& at(std::size_t i) const noexcept(false) {
1142 : (std::__throw_out_of_range("Out of range in BasicFixedString::at"),
1147 * \pre `i <= size()`
1148 * \note `(*this)[size()]` is allowed will return `Char(0)`.
1149 * \return `*(data() + i)`
1151 FOLLY_CPP14_CONSTEXPR Char& operator[](std::size_t i) noexcept {
1155 return data_[detail::fixedstring::checkOverflow(i, size_)];
1162 constexpr const Char& operator[](std::size_t i) const noexcept {
1166 return data_[detail::fixedstring::checkOverflow(i, size_)];
1171 * \note Equivalent to `(*this)[0]`
1173 FOLLY_CPP14_CONSTEXPR Char& front() noexcept {
1180 constexpr const Char& front() const noexcept {
1185 * \note Equivalent to `at(size()-1)`
1188 FOLLY_CPP14_CONSTEXPR Char& back() noexcept {
1190 return data_[size_ - 1u];
1192 return data_[size_ - detail::fixedstring::checkOverflow(1u, size_)];
1199 constexpr const Char& back() const noexcept {
1201 return data_[size_ - 1u];
1203 return data_[size_ - detail::fixedstring::checkOverflow(1u, size_)];
1208 * Clears the contents of this string.
1209 * \post `size() == 0u`
1210 * \post `at(size()) == Char(0)`
1212 FOLLY_CPP14_CONSTEXPR void clear() noexcept {
1213 data_[0u] = Char(0);
1218 * \note Equivalent to `append(1u, ch)`.
1220 FOLLY_CPP14_CONSTEXPR void push_back(Char ch) noexcept(false) {
1221 detail::fixedstring::checkOverflow(1u, N - size_);
1223 data_[++size_] = Char(0);
1227 * \note Equivalent to `cappend(1u, ch)`.
1229 constexpr BasicFixedString<Char, N + 1u> cpush_back(Char ch) const noexcept {
1234 * Removes the last character from the string.
1236 * \post `size()` is one fewer than before calling `pop_back()`.
1237 * \post `at(size()) == Char(0)`
1238 * \post The characters in the half-open range `[0,size()-1)` are unmodified.
1239 * \throw std::out_of_range if empty().
1241 FOLLY_CPP14_CONSTEXPR void pop_back() noexcept(false) {
1242 detail::fixedstring::checkOverflow(1u, size_);
1244 data_[size_] = Char(0);
1248 * Returns a new string with the first `size()-1` characters from this string.
1250 * \note Equivalent to `BasicFixedString<Char, N-1u>{*this, 0u, size()-1u}`
1251 * \throw std::out_of_range if empty().
1253 constexpr BasicFixedString<Char, N - 1u> cpop_back() const noexcept(false) {
1254 return {*this, 0u, size_ - detail::fixedstring::checkOverflow(1u, size_)};
1257 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1258 * Appends `count` copies of `ch` to this string.
1259 * \pre `count + old_size <= N`
1260 * \post The first `old_size` characters of the string are unmodified.
1261 * \post `size() == old_size + count`
1262 * \throw std::out_of_range if count > N - size().
1264 FOLLY_CPP14_CONSTEXPR BasicFixedString& append(
1266 Char ch) noexcept(false) {
1267 detail::fixedstring::checkOverflow(count, N - size_);
1268 for (std::size_t i = 0u; i < count; ++i)
1269 data_[size_ + i] = ch;
1271 data_[size_] = Char(0);
1276 * \note Equivalent to `append(*this, 0, that.size())`.
1278 template <std::size_t M>
1279 FOLLY_CPP14_CONSTEXPR BasicFixedString& append(
1280 const BasicFixedString<Char, M>& that) noexcept(false) {
1281 return append(that, 0u, that.size_);
1284 // Why is this overload deleted? So as not to get confused with
1285 // append("null-terminated", N), where N would be a count instead
1287 template <std::size_t M>
1288 FOLLY_CPP14_CONSTEXPR BasicFixedString& append(
1289 const BasicFixedString<Char, M>& that,
1290 std::size_t pos) noexcept(false) = delete;
1293 * Appends `count` characters from another string to this one, starting at a
1294 * given offset, `pos`.
1295 * \param that The source string.
1296 * \param pos The starting position in the source string.
1297 * \param count The number of characters to append. If `npos`, `count` is
1298 * taken to be `that.size()-pos`.
1299 * \pre `pos <= that.size()`
1300 * \pre `count <= that.size() - pos`
1301 * \pre `old_size + count <= N`
1302 * \post The first `old_size` characters of the string are unmodified.
1303 * \post `size() == old_size + count`
1304 * \post `at(size()) == Char(0)`
1305 * \throw std::out_of_range if pos + count > that.size() or if
1306 * `old_size + count > N`.
1308 template <std::size_t M>
1309 FOLLY_CPP14_CONSTEXPR BasicFixedString& append(
1310 const BasicFixedString<Char, M>& that,
1312 std::size_t count) noexcept(false) {
1313 detail::fixedstring::checkOverflow(pos, that.size_);
1314 count = detail::fixedstring::checkOverflowOrNpos(count, that.size_ - pos);
1315 detail::fixedstring::checkOverflow(count, N - size_);
1316 for (std::size_t i = 0u; i < count; ++i)
1317 data_[size_ + i] = that.data_[pos + i];
1319 data_[size_] = Char(0);
1324 * \note Equivalent to `append(that, strlen(that))`.
1326 FOLLY_CPP14_CONSTEXPR BasicFixedString& append(const Char* that) noexcept(
1328 return append(that, folly::constexpr_strlen(that));
1332 * Appends `count` characters from the specified character array.
1333 * \pre `that` points to a range of at least `count` characters.
1334 * \pre `count + old_size <= N`
1335 * \post The first `old_size` characters of the string are unmodified.
1336 * \post `size() == old_size + count`
1337 * \post `at(size()) == Char(0)`
1338 * \throw std::out_of_range if old_size + count > N.
1340 FOLLY_CPP14_CONSTEXPR BasicFixedString& append(
1342 std::size_t count) noexcept(false) {
1343 detail::fixedstring::checkOverflow(count, N - size_);
1344 for (std::size_t i = 0u; i < count; ++i)
1345 data_[size_ + i] = that[i];
1347 data_[size_] = Char(0);
1351 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1352 * Creates a new string by appending a character to an existing string, which
1353 * is left unmodified.
1354 * \note Equivalent to `*this + ch`
1356 constexpr BasicFixedString<Char, N + 1u> cappend(Char ch) const noexcept {
1361 * Creates a new string by appending a string to an existing string, which
1362 * is left unmodified.
1363 * \note Equivalent to `*this + ch`
1365 template <std::size_t M>
1366 constexpr BasicFixedString<Char, N + M> cappend(
1367 const BasicFixedString<Char, M>& that) const noexcept {
1368 return *this + that;
1371 // Deleted to avoid confusion with append("char*", N), where N is a count
1372 // instead of a position.
1373 template <std::size_t M>
1374 constexpr BasicFixedString<Char, N + M> cappend(
1375 const BasicFixedString<Char, M>& that,
1376 std::size_t pos) const noexcept(false) = delete;
1379 * Creates a new string by appending characters from one string to another,
1380 * which is left unmodified.
1381 * \note Equivalent to `*this + that.substr(pos, count)`
1383 template <std::size_t M>
1384 constexpr BasicFixedString<Char, N + M> cappend(
1385 const BasicFixedString<Char, M>& that,
1387 std::size_t count) const noexcept(false) {
1388 return creplace(size_, 0u, that, pos, count);
1392 * Creates a new string by appending a string literal to a string,
1393 * which is left unmodified.
1394 * \note Equivalent to `*this + that`
1396 template <std::size_t M>
1397 constexpr BasicFixedString<Char, N + M - 1u> cappend(
1398 const Char (&that)[M]) const noexcept {
1399 return creplace(size_, 0u, that);
1402 // Deleted to avoid confusion with append("char*", N), where N is a count
1403 // instead of a position
1404 template <std::size_t M>
1405 constexpr BasicFixedString<Char, N + M - 1u> cappend(
1406 const Char (&that)[M],
1407 std::size_t pos) const noexcept(false) = delete;
1410 * Creates a new string by appending characters from one string to another,
1411 * which is left unmodified.
1412 * \note Equivalent to `*this + makeFixedString(that).substr(pos, count)`
1414 template <std::size_t M>
1415 constexpr BasicFixedString<Char, N + M - 1u>
1416 cappend(const Char (&that)[M], std::size_t pos, std::size_t count) const
1418 return creplace(size_, 0u, that, pos, count);
1421 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1422 * Appends characters from a null-terminated string literal to this string.
1423 * \note Equivalent to `append(that)`.
1425 FOLLY_CPP14_CONSTEXPR BasicFixedString& operator+=(const Char* that) noexcept(
1427 return append(that);
1431 * Appends characters from another string to this one.
1432 * \note Equivalent to `append(that)`.
1434 template <std::size_t M>
1435 FOLLY_CPP14_CONSTEXPR BasicFixedString& operator+=(
1436 const BasicFixedString<Char, M>& that) noexcept(false) {
1437 return append(that, 0u, that.size_);
1441 * Appends a character to this string.
1442 * \note Equivalent to `push_back(ch)`.
1444 FOLLY_CPP14_CONSTEXPR BasicFixedString& operator+=(Char ch) noexcept(false) {
1450 * Appends characters from an `initializer_list` to this string.
1451 * \note Equivalent to `append(il.begin(), il.size())`.
1453 FOLLY_CPP14_CONSTEXPR BasicFixedString& operator+=(
1454 std::initializer_list<Char> il) noexcept(false) {
1455 return append(il.begin(), il.size());
1458 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1459 * Erase all characters from this string.
1460 * \note Equivalent to `clear()`
1463 FOLLY_CPP14_CONSTEXPR BasicFixedString& erase() noexcept {
1469 * Erases `count` characters from position `pos`. If `count` is `npos`,
1470 * erases from `pos` to the end of the string.
1471 * \pre `pos <= size()`
1472 * \pre `count <= size() - pos || count == npos`
1473 * \post `size() == old_size - min(count, old_size - pos)`
1474 * \post `at(size()) == Char(0)`
1476 * \throw std::out_of_range when pos > size().
1478 FOLLY_CPP14_CONSTEXPR BasicFixedString& erase(
1480 std::size_t count = npos) noexcept(false) {
1481 using A = const Char[1];
1484 detail::fixedstring::checkOverflowOrNpos(
1485 count, size_ - detail::fixedstring::checkOverflow(pos, size_)),
1491 * \note Equivalent to `erase(first - data(), 1)`
1492 * \return A pointer to the first character after the erased character.
1494 FOLLY_CPP14_CONSTEXPR Char* erase(const Char* first) noexcept(false) {
1495 erase(first - data_, 1u);
1496 return data_ + (first - data_);
1500 * \note Equivalent to `erase(first - data(), last - first)`
1501 * \return A pointer to the first character after the erased characters.
1503 FOLLY_CPP14_CONSTEXPR Char* erase(
1505 const Char* last) noexcept(false) {
1506 erase(first - data_, last - first);
1507 return data_ + (first - data_);
1510 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1511 * Create a new string by erasing all the characters from this string.
1512 * \note Equivalent to `BasicFixedString<Char, 0>{}`
1514 constexpr BasicFixedString<Char, 0u> cerase() const noexcept {
1519 * Create a new string by erasing all the characters after position `pos` from
1521 * \note Equivalent to `creplace(pos, min(count, pos - size()), "")`
1523 constexpr BasicFixedString cerase(std::size_t pos, std::size_t count = npos)
1524 const noexcept(false) {
1525 using A = const Char[1];
1528 detail::fixedstring::checkOverflowOrNpos(
1529 count, size_ - detail::fixedstring::checkOverflow(pos, size_)),
1533 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1534 * Compare two strings for lexicographical ordering.
1535 * \note Equivalent to
1536 * `compare(0, size(), that.data(), that.size())`
1538 template <std::size_t M>
1539 constexpr int compare(const BasicFixedString<Char, M>& that) const noexcept {
1540 return compare(0u, size_, that, 0u, that.size_);
1544 * Compare two strings for lexicographical ordering.
1545 * \note Equivalent to
1546 * `compare(this_pos, this_count, that.data(), that.size())`
1548 template <std::size_t M>
1549 constexpr int compare(
1550 std::size_t this_pos,
1551 std::size_t this_count,
1552 const BasicFixedString<Char, M>& that) const noexcept(false) {
1553 return compare(this_pos, this_count, that, 0u, that.size_);
1557 * Compare two strings for lexicographical ordering.
1558 * \note Equivalent to
1559 * `compare(this_pos, this_count, that.data() + that_pos, that_count)`
1561 template <std::size_t M>
1562 constexpr int compare(
1563 std::size_t this_pos,
1564 std::size_t this_count,
1565 const BasicFixedString<Char, M>& that,
1566 std::size_t that_pos,
1567 std::size_t that_count) const noexcept(false) {
1568 return static_cast<int>(detail::fixedstring::compare_(
1570 detail::fixedstring::checkOverflow(this_pos, size_),
1571 detail::fixedstring::checkOverflow(this_count, size_ - this_pos) +
1574 detail::fixedstring::checkOverflow(that_pos, that.size_),
1575 detail::fixedstring::checkOverflow(that_count, that.size_ - that_pos) +
1580 * Compare two strings for lexicographical ordering.
1581 * \note Equivalent to `compare(0, size(), that, strlen(that))`
1583 constexpr int compare(const Char* that) const noexcept {
1584 return compare(0u, size_, that, folly::constexpr_strlen(that));
1590 constexpr int compare(Range<const Char*> that) const noexcept {
1591 return compare(0u, size_, that.begin(), that.size());
1595 * Compare two strings for lexicographical ordering.
1596 * \note Equivalent to
1597 * `compare(this_pos, this_count, that, strlen(that))`
1599 constexpr int compare(
1600 std::size_t this_pos,
1601 std::size_t this_count,
1602 const Char* that) const noexcept(false) {
1603 return compare(this_pos, this_count, that, folly::constexpr_strlen(that));
1609 constexpr int compare(
1610 std::size_t this_pos,
1611 std::size_t this_count,
1612 Range<const Char*> that) const noexcept(false) {
1613 return compare(this_pos, this_count, that.begin(), that.size());
1617 * Compare two strings for lexicographical ordering.
1619 * Let `A` be the the
1620 * character sequence {`(*this)[this_pos]`, ...
1621 * `(*this)[this_pos + this_count - 1]`}. Let `B` be the character sequence
1622 * {`that[0]`, ...`that[count - 1]`}. Then...
1625 * - `< 0` if `A` is ordered before the `B`
1626 * - `> 0` if `B` is ordered before `A`
1627 * - `0` if `A` equals `B`.
1629 * \throw std::out_of_range if this_pos + this_count > size().
1631 constexpr int compare(
1632 std::size_t this_pos,
1633 std::size_t this_count,
1635 std::size_t that_count) const noexcept(false) {
1636 return static_cast<int>(detail::fixedstring::compare_(
1638 detail::fixedstring::checkOverflow(this_pos, size_),
1639 detail::fixedstring::checkOverflowOrNpos(this_count, size_ - this_pos) +
1646 constexpr int compare(
1647 std::size_t this_pos,
1648 std::size_t this_count,
1649 Range<const Char*> that,
1650 std::size_t that_count) const noexcept(false) {
1655 detail::fixedstring::checkOverflow(that_count, that.size()));
1658 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1659 * Return a substring from `pos` to the end of the string.
1660 * \note Equivalent to `BasicFixedString{*this, pos}`
1662 constexpr BasicFixedString substr(std::size_t pos) const noexcept(false) {
1663 return {*this, pos};
1667 * Return a substring from `pos` to the end of the string.
1668 * \note Equivalent to `BasicFixedString{*this, pos, count}`
1670 constexpr BasicFixedString substr(std::size_t pos, std::size_t count) const
1672 return {*this, pos, count};
1675 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1676 * Replace the characters in the range denoted by the half-open range
1677 * [`first`, `last`) with the string `that`.
1678 * \pre `first` and `last` point to characters within this string (including
1679 * the terminating null).
1680 * \note Equivalent to
1681 * `replace(first - data(), last - first, that.data(), that.size())`
1683 template <std::size_t M>
1684 FOLLY_CPP14_CONSTEXPR BasicFixedString& replace(
1687 const BasicFixedString<Char, M>& that) noexcept(false) {
1688 return replace(first - data_, last - first, that, 0u, that.size_);
1692 * Replace `this_count` characters starting from position `this_pos` with the
1693 * characters from string `that` starting at position `that_pos`.
1694 * \pre `that_pos <= that.size()`
1695 * \note Equivalent to
1696 * <tt>replace(this_pos, this_count, that.data() + that_pos,
1697 * that.size() - that_pos)</tt>
1699 template <std::size_t M>
1700 FOLLY_CPP14_CONSTEXPR BasicFixedString& replace(
1701 std::size_t this_pos,
1702 std::size_t this_count,
1703 const BasicFixedString<Char, M>& that,
1704 std::size_t that_pos = 0u) noexcept(false) {
1705 return replace(this_pos, this_count, that, that_pos, that.size_ - that_pos);
1709 * Replace `this_count` characters starting from position `this_pos` with
1710 * `that_count` characters from string `that` starting at position
1712 * \pre `that_pos <= that.size() && that_count <= that.size() - that_pos`
1713 * \note Equivalent to
1714 * `replace(this_pos, this_count, that.data() + that_pos, that_count)`
1716 template <std::size_t M>
1717 FOLLY_CPP14_CONSTEXPR BasicFixedString& replace(
1718 std::size_t this_pos,
1719 std::size_t this_count,
1720 const BasicFixedString<Char, M>& that,
1721 std::size_t that_pos,
1722 std::size_t that_count) noexcept(false) {
1723 return *this = creplace(this_pos, this_count, that, that_pos, that_count);
1727 * Replace `this_count` characters starting from position `this_pos` with
1728 * the characters from the string literal `that`.
1729 * \note Equivalent to
1730 * `replace(this_pos, this_count, that, strlen(that))`
1732 FOLLY_CPP14_CONSTEXPR BasicFixedString& replace(
1733 std::size_t this_pos,
1734 std::size_t this_count,
1735 const Char* that) noexcept(false) {
1736 return replace(this_pos, this_count, that, folly::constexpr_strlen(that));
1740 * Replace the characters denoted by the half-open range [`first`,`last`) with
1741 * the characters from the string literal `that`.
1742 * \pre `first` and `last` point to characters within this string (including
1743 * the terminating null).
1744 * \note Equivalent to
1745 * `replace(first - data(), last - first, that, strlen(that))`
1747 FOLLY_CPP14_CONSTEXPR BasicFixedString& replace(
1750 const Char* that) noexcept(false) {
1752 first - data_, last - first, that, folly::constexpr_strlen(that));
1756 * Replace `this_count` characters starting from position `this_pos` with
1757 * `that_count` characters from the character sequence pointed to by `that`.
1758 * \param this_pos The starting offset within `*this` of the first character
1760 * \param this_count The number of characters to be replaced. If `npos`,
1761 * it is treated as if `this_count` were `size() - this_pos`.
1762 * \param that A pointer to the replacement string.
1763 * \param that_count The number of characters in the replacement string.
1764 * \pre `this_pos <= size() && this_count <= size() - this_pos`
1765 * \pre `that` points to a contiguous sequence of at least `that_count`
1767 * \throw std::out_of_range on any of the following conditions:
1768 * - `this_pos > size()`
1769 * - `this_count > size() - this_pos`
1770 * - `size() - this_count + that_count > N`
1772 FOLLY_CPP14_CONSTEXPR BasicFixedString& replace(
1773 std::size_t this_pos,
1774 std::size_t this_count,
1776 std::size_t that_count) noexcept(false) {
1777 return *this = detail::fixedstring::Helper::replace_<Char>(
1780 detail::fixedstring::checkOverflow(this_pos, size_),
1781 detail::fixedstring::checkOverflowOrNpos(
1782 this_count, size_ - this_pos),
1790 * Replace `this_count` characters starting from position `this_pos` with
1791 * `that_count` characters `ch`.
1792 * \note Equivalent to
1793 * `replace(this_pos, this_count, BasicFixedString{that_count, ch})`
1795 FOLLY_CPP14_CONSTEXPR BasicFixedString& replace(
1796 std::size_t this_pos,
1797 std::size_t this_count,
1798 std::size_t that_count,
1799 Char ch) noexcept(false) {
1800 return replace(this_pos, this_count, BasicFixedString{that_count, ch});
1804 * Replace the characters denoted by the half-open range [`first`,`last`)
1805 * with `that_count` characters `ch`.
1806 * \note Equivalent to
1807 * `replace(first - data(), last - first, BasicFixedString{that_count, ch})`
1809 FOLLY_CPP14_CONSTEXPR BasicFixedString& replace(
1812 std::size_t that_count,
1813 Char ch) noexcept(false) {
1815 first - data_, last - first, BasicFixedString{that_count, ch});
1819 * Replace the characters denoted by the half-open range [`first`,`last`) with
1820 * the characters from the string literal `that`.
1821 * \pre `first` and `last` point to characters within this string (including
1822 * the terminating null).
1823 * \note Equivalent to
1824 * `replace(this_pos, this_count, il.begin(), il.size())`
1826 FOLLY_CPP14_CONSTEXPR BasicFixedString& replace(
1829 std::initializer_list<Char> il) noexcept(false) {
1830 return replace(first - data_, last - first, il.begin(), il.size());
1833 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1834 * Construct a new string by replacing `this_count` characters starting from
1835 * position `this_pos` within this string with the characters from string
1836 * `that` starting at position `that_pos`.
1837 * \pre `that_pos <= that.size()`
1838 * \note Equivalent to
1839 * <tt>creplace(this_pos, this_count, that, that_pos,
1840 * that.size() - that_pos)</tt>
1842 template <std::size_t M>
1843 constexpr BasicFixedString<Char, N + M> creplace(
1844 std::size_t this_pos,
1845 std::size_t this_count,
1846 const BasicFixedString<Char, M>& that,
1847 std::size_t that_pos = 0u) const noexcept(false) {
1853 that.size_ - detail::fixedstring::checkOverflow(that_pos, that.size_));
1857 * Construct a new string by replacing `this_count` characters starting from
1858 * position `this_pos` within this string with `that_count` characters from
1859 * string `that` starting at position `that_pos`.
1860 * \param this_pos The starting offset within `*this` of the first character
1862 * \param this_count The number of characters to be replaced. If `npos`,
1863 * it is treated as if `this_count` were `size() - this_pos`.
1864 * \param that A string that contains the replacement string.
1865 * \param that_pos The offset to the first character in the replacement
1867 * \param that_count The number of characters in the replacement string.
1868 * \pre `this_pos <= size() && this_count <= size() - this_pos`
1869 * \pre `that_pos <= that.size() && that_count <= that.size() - that_pos`
1870 * \post The size of the returned string is `size() - this_count + that_count`
1871 * \note Equivalent to <tt>BasicFixedString<Char, N + M>{substr(0, this_pos) +
1872 * that.substr(that_pos, that_count) + substr(this_pos + this_count)}</tt>
1873 * \throw std::out_of_range on any of the following conditions:
1874 * - `this_pos > size()`
1875 * - `this_count > size() - this_pos`
1876 * - `that_pos > that.size()`
1877 * - `that_count > that.size() - that_pos`
1879 template <std::size_t M>
1880 constexpr BasicFixedString<Char, N + M> creplace(
1881 std::size_t this_pos,
1882 std::size_t this_count,
1883 const BasicFixedString<Char, M>& that,
1884 std::size_t that_pos,
1885 std::size_t that_count) const noexcept(false) {
1886 return detail::fixedstring::Helper::replace_<Char>(
1889 detail::fixedstring::checkOverflow(this_pos, size_),
1890 detail::fixedstring::checkOverflowOrNpos(this_count, size_ - this_pos),
1892 detail::fixedstring::checkOverflow(that_pos, that.size_),
1893 detail::fixedstring::checkOverflowOrNpos(
1894 that_count, that.size_ - that_pos),
1895 folly::make_index_sequence<N + M>{});
1899 * Construct a new string by replacing the characters denoted by the half-open
1900 * range [`first`,`last`) within this string with the characters from string
1901 * `that` starting at position `that_pos`.
1902 * \pre `that_pos <= that.size()`
1903 * \note Equivalent to
1904 * <tt>creplace(first - data(), last - first, that, that_pos,
1905 * that.size() - that_pos)</tt>
1907 template <std::size_t M>
1908 constexpr BasicFixedString<Char, N + M> creplace(
1911 const BasicFixedString<Char, M>& that,
1912 std::size_t that_pos = 0u) const noexcept(false) {
1918 that.size_ - detail::fixedstring::checkOverflow(that_pos, that.size_));
1922 * Construct a new string by replacing the characters denoted by the half-open
1923 * range [`first`,`last`) within this string with the `that_count`
1924 * characters from string `that` starting at position `that_pos`.
1925 * \note Equivalent to
1926 * <tt>creplace(first - data(), last - first, that, that_pos,
1929 template <std::size_t M>
1930 constexpr BasicFixedString<Char, N + M> creplace(
1933 const BasicFixedString<Char, M>& that,
1934 std::size_t that_pos,
1935 std::size_t that_count) const noexcept(false) {
1936 return creplace(first - data_, last - first, that, that_pos, that_count);
1940 * Construct a new string by replacing `this_count` characters starting from
1941 * position `this_pos` within this string with `M-1` characters from
1942 * character array `that`.
1943 * \pre `strlen(that) == M-1`
1944 * \note Equivalent to
1945 * <tt>creplace(this_pos, this_count, that, 0, M - 1)</tt>
1947 template <std::size_t M>
1948 constexpr BasicFixedString<Char, N + M - 1u> creplace(
1949 std::size_t this_pos,
1950 std::size_t this_count,
1951 const Char (&that)[M]) const noexcept(false) {
1952 return creplace(this_pos, this_count, that, 0u, M - 1u);
1956 * Replace `this_count` characters starting from position `this_pos` with
1957 * `that_count` characters from the character array `that` starting at
1958 * position `that_pos`.
1959 * \param this_pos The starting offset within `*this` of the first character
1961 * \param this_count The number of characters to be replaced. If `npos`,
1962 * it is treated as if `this_count` were `size() - this_pos`.
1963 * \param that An array of characters containing the replacement string.
1964 * \param that_pos The starting offset of the replacement string.
1965 * \param that_count The number of characters in the replacement string. If
1966 * `npos`, it is treated as if `that_count` were `M - 1 - that_pos`
1967 * \pre `this_pos <= size() && this_count <= size() - this_pos`
1968 * \pre `that_pos <= M - 1 && that_count <= M - 1 - that_pos`
1969 * \post The size of the returned string is `size() - this_count + that_count`
1970 * \note Equivalent to <tt>BasicFixedString<Char, N + M - 1>{
1971 * substr(0, this_pos) +
1972 * makeFixedString(that).substr(that_pos, that_count) +
1973 * substr(this_pos + this_count)}</tt>
1974 * \throw std::out_of_range on any of the following conditions:
1975 * - `this_pos > size()`
1976 * - `this_count > size() - this_pos`
1978 * - `that_count >= M - that_pos`
1980 template <std::size_t M>
1981 constexpr BasicFixedString<Char, N + M - 1u> creplace(
1982 std::size_t this_pos,
1983 std::size_t this_count,
1984 const Char (&that)[M],
1985 std::size_t that_pos,
1986 std::size_t that_count) const noexcept(false) {
1987 return detail::fixedstring::Helper::replace_<Char>(
1990 detail::fixedstring::checkOverflow(this_pos, size_),
1991 detail::fixedstring::checkOverflowOrNpos(this_count, size_ - this_pos),
1992 detail::fixedstring::checkNullTerminated(that),
1993 detail::fixedstring::checkOverflow(that_pos, M - 1u),
1994 detail::fixedstring::checkOverflowOrNpos(that_count, M - 1u - that_pos),
1995 folly::make_index_sequence<N + M - 1u>{});
1999 * Construct a new string by replacing the characters denoted by the half-open
2000 * range [`first`,`last`) within this string with the first `M-1`
2001 * characters from the character array `that`.
2002 * \pre `strlen(that) == M-1`
2003 * \note Equivalent to
2004 * <tt>creplace(first - data(), last - first, that, 0, M-1)</tt>
2006 template <std::size_t M>
2007 constexpr BasicFixedString<Char, N + M - 1u>
2008 creplace(const Char* first, const Char* last, const Char (&that)[M]) const
2010 return creplace(first - data_, last - first, that, 0u, M - 1u);
2014 * Construct a new string by replacing the characters denoted by the half-open
2015 * range [`first`,`last`) within this string with the `that_count`
2016 * characters from the character array `that` starting at position
2018 * \pre `strlen(that) == M-1`
2019 * \note Equivalent to
2020 * `creplace(first - data(), last - first, that, that_pos, that_count)`
2022 template <std::size_t M>
2023 constexpr BasicFixedString<Char, N + M - 1u> creplace(
2026 const Char (&that)[M],
2027 std::size_t that_pos,
2028 std::size_t that_count) const noexcept(false) {
2029 return creplace(first - data_, last - first, that, that_pos, that_count);
2032 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
2033 * Copies `min(count, size())` characters starting from offset `0`
2034 * from this string into the buffer pointed to by `dest`.
2035 * \return The number of characters copied.
2037 FOLLY_CPP14_CONSTEXPR std::size_t copy(Char* dest, std::size_t count) const
2039 return copy(dest, count, 0u);
2043 * Copies `min(count, size() - pos)` characters starting from offset `pos`
2044 * from this string into the buffer pointed to by `dest`.
2045 * \pre `pos <= size()`
2046 * \return The number of characters copied.
2047 * \throw std::out_of_range if `pos > size()`
2049 FOLLY_CPP14_CONSTEXPR std::size_t
2050 copy(Char* dest, std::size_t count, std::size_t pos) const noexcept(false) {
2051 detail::fixedstring::checkOverflow(pos, size_);
2052 for (std::size_t i = 0u; i < count; ++i) {
2053 if (i + pos == size_)
2055 dest[i] = data_[i + pos];
2060 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
2061 * Resizes the current string.
2062 * \note Equivalent to `resize(count, Char(0))`
2064 FOLLY_CPP14_CONSTEXPR void resize(std::size_t count) noexcept(false) {
2065 resize(count, Char(0));
2069 * Resizes the current string by setting the size to `count` and setting
2070 * `data()[count]` to `Char(0)`. If `count > old_size`, the characters
2071 * in the range [`old_size`,`count`) are set to `ch`.
2073 FOLLY_CPP14_CONSTEXPR void resize(std::size_t count, Char ch) noexcept(
2075 detail::fixedstring::checkOverflow(count, N);
2076 if (count == size_) {
2077 } else if (count < size_) {
2079 data_[size_] = Char(0);
2081 for (; size_ < count; ++size_) {
2084 data_[size_] = Char(0);
2088 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
2089 * Finds the first occurrence of the character sequence `that` in this string.
2090 * \note Equivalent to `find(that.data(), 0, that.size())`
2092 template <std::size_t M>
2093 constexpr std::size_t find(const BasicFixedString<Char, M>& that) const
2095 return find(that, 0u);
2099 * Finds the first occurrence of the character sequence `that` in this string,
2100 * starting at offset `pos`.
2101 * \pre `pos <= size()`
2102 * \note Equivalent to `find(that.data(), pos, that.size())`
2104 template <std::size_t M>
2105 constexpr std::size_t find(
2106 const BasicFixedString<Char, M>& that,
2107 std::size_t pos) const noexcept(false) {
2108 return that.size_ <= size_ - detail::fixedstring::checkOverflow(pos, size_)
2109 ? detail::fixedstring::find_(data_, size_, that.data_, pos, that.size_)
2114 * Finds the first occurrence of the character sequence `that` in this string.
2115 * \note Equivalent to `find(that.data(), 0, strlen(that))`
2117 constexpr std::size_t find(const Char* that) const noexcept {
2118 return find(that, 0u, folly::constexpr_strlen(that));
2122 * Finds the first occurrence of the character sequence `that` in this string,
2123 * starting at offset `pos`.
2124 * \pre `pos <= size()`
2125 * \note Equivalent to `find(that.data(), pos, strlen(that))`
2127 constexpr std::size_t find(const Char* that, std::size_t pos) const
2129 return find(that, pos, folly::constexpr_strlen(that));
2133 * Finds the first occurrence of the first `count` characters in the buffer
2134 * pointed to by `that` in this string, starting at offset `pos`.
2135 * \pre `pos <= size()`
2136 * \pre `that` points to a buffer containing at least `count` contiguous
2138 * \return The lowest offset `i` such that `i >= pos` and
2139 * `0 == strncmp(data() + i, that, count)`; or `npos` if there is no such
2141 * \throw std::out_of_range when `pos > size()`
2143 constexpr std::size_t find(
2146 std::size_t count) const noexcept(false) {
2147 return count <= size_ - detail::fixedstring::checkOverflow(pos, size_)
2148 ? detail::fixedstring::find_(data_, size_, that, pos, count)
2153 * Finds the first occurrence of the character `ch` in this string.
2154 * \note Equivalent to `find(&ch, 0, 1)`
2156 constexpr std::size_t find(Char ch) const noexcept {
2157 return find(ch, 0u);
2161 * Finds the first occurrence of the character character `c` in this string,
2162 * starting at offset `pos`.
2163 * \pre `pos <= size()`
2164 * \note Equivalent to `find(&ch, pos, 1)`
2166 constexpr std::size_t find(Char ch, std::size_t pos) const noexcept(false) {
2167 using A = const Char[1u];
2168 return 0u == size_ - detail::fixedstring::checkOverflow(pos, size_)
2170 : detail::fixedstring::find_(data_, size_, A{ch}, pos, 1u);
2173 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
2174 * Finds the last occurrence of characters in the string
2175 * `that` in this string.
2176 * \note Equivalent to `rfind(that.data(), size(), that.size())`
2178 template <std::size_t M>
2179 constexpr std::size_t rfind(const BasicFixedString<Char, M>& that) const
2181 return rfind(that, size_);
2185 * Finds the last occurrence of characters in the string
2186 * `that` in this string, starting at offset `pos`.
2187 * \note Equivalent to `rfind(that.data(), pos, that.size())`
2189 template <std::size_t M>
2190 constexpr std::size_t rfind(
2191 const BasicFixedString<Char, M>& that,
2192 std::size_t pos) const noexcept(false) {
2193 return that.size_ <= size_
2194 ? detail::fixedstring::rfind_(
2197 folly::constexpr_min(
2198 detail::fixedstring::checkOverflow(pos, size_),
2199 size_ - that.size_),
2205 * Finds the last occurrence of characters in the buffer
2206 * pointed to by `that` in this string.
2207 * \note Equivalent to `rfind(that, size(), strlen(that))`
2209 constexpr std::size_t rfind(const Char* that) const noexcept {
2210 return rfind(that, size_, folly::constexpr_strlen(that));
2214 * Finds the last occurrence of characters in the buffer
2215 * pointed to by `that` in this string, starting at offset `pos`.
2216 * \note Equivalent to `rfind(that, pos, strlen(that))`
2218 constexpr std::size_t rfind(const Char* that, std::size_t pos) const
2220 return rfind(that, pos, folly::constexpr_strlen(that));
2224 * Finds the last occurrence of the first `count` characters in the buffer
2225 * pointed to by `that` in this string, starting at offset `pos`.
2226 * \pre `pos <= size()`
2227 * \pre `that` points to a buffer containing at least `count` contiguous
2229 * \return The largest offset `i` such that `i <= pos` and
2230 * `i + count <= size()` and `0 == strncmp(data() + i, that, count)`; or
2231 * `npos` if there is no such offset `i`.
2232 * \throw std::out_of_range when `pos > size()`
2234 constexpr std::size_t rfind(
2237 std::size_t count) const noexcept(false) {
2238 return count <= size_
2239 ? detail::fixedstring::rfind_(
2242 folly::constexpr_min(
2243 detail::fixedstring::checkOverflow(pos, size_),
2250 * Finds the last occurrence of the character character `ch` in this string.
2251 * \note Equivalent to `rfind(&ch, size(), 1)`
2253 constexpr std::size_t rfind(Char ch) const noexcept {
2254 return rfind(ch, size_);
2258 * Finds the last occurrence of the character character `ch` in this string,
2259 * starting at offset `pos`.
2260 * \pre `pos <= size()`
2261 * \note Equivalent to `rfind(&ch, pos, 1)`
2263 constexpr std::size_t rfind(Char ch, std::size_t pos) const noexcept(false) {
2264 using A = const Char[1u];
2267 : detail::fixedstring::rfind_(
2270 folly::constexpr_min(
2271 detail::fixedstring::checkOverflow(pos, size_), size_ - 1u),
2275 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
2276 * Finds the first occurrence of any character in `that` in this string.
2277 * \note Equivalent to `find_first_of(that.data(), 0, that.size())`
2279 template <std::size_t M>
2280 constexpr std::size_t find_first_of(
2281 const BasicFixedString<Char, M>& that) const noexcept {
2282 return find_first_of(that, 0u);
2286 * Finds the first occurrence of any character in `that` in this string,
2287 * starting at offset `pos`
2288 * \note Equivalent to `find_first_of(that.data(), pos, that.size())`
2290 template <std::size_t M>
2291 constexpr std::size_t find_first_of(
2292 const BasicFixedString<Char, M>& that,
2293 std::size_t pos) const noexcept(false) {
2294 return size_ == detail::fixedstring::checkOverflow(pos, size_)
2296 : detail::fixedstring::find_first_of_(
2297 data_, size_, that.data_, pos, that.size_);
2301 * Finds the first occurrence of any character in the null-terminated
2302 * character sequence pointed to by `that` in this string.
2303 * \note Equivalent to `find_first_of(that, 0, strlen(that))`
2305 constexpr std::size_t find_first_of(const Char* that) const noexcept {
2306 return find_first_of(that, 0u, folly::constexpr_strlen(that));
2310 * Finds the first occurrence of any character in the null-terminated
2311 * character sequence pointed to by `that` in this string,
2312 * starting at offset `pos`
2313 * \note Equivalent to `find_first_of(that, pos, strlen(that))`
2315 constexpr std::size_t find_first_of(const Char* that, std::size_t pos) const
2317 return find_first_of(that, pos, folly::constexpr_strlen(that));
2321 * Finds the first occurrence of any character in the first `count` characters
2322 * in the buffer pointed to by `that` in this string, starting at offset
2324 * \pre `pos <= size()`
2325 * \pre `that` points to a buffer containing at least `count` contiguous
2327 * \return The smallest offset `i` such that `i >= pos` and
2328 * `std::find(that, that+count, at(i)) != that+count`; or
2329 * `npos` if there is no such offset `i`.
2330 * \throw std::out_of_range when `pos > size()`
2332 constexpr std::size_t find_first_of(
2335 std::size_t count) const noexcept(false) {
2336 return size_ == detail::fixedstring::checkOverflow(pos, size_)
2338 : detail::fixedstring::find_first_of_(data_, size_, that, pos, count);
2342 * Finds the first occurrence of `ch` in this string.
2343 * \note Equivalent to `find_first_of(&ch, 0, 1)`
2345 constexpr std::size_t find_first_of(Char ch) const noexcept {
2346 return find_first_of(ch, 0u);
2350 * Finds the first occurrence of `ch` in this string,
2351 * starting at offset `pos`.
2352 * \note Equivalent to `find_first_of(&ch, pos, 1)`
2354 constexpr std::size_t find_first_of(Char ch, std::size_t pos) const
2356 using A = const Char[1u];
2357 return size_ == detail::fixedstring::checkOverflow(pos, size_)
2359 : detail::fixedstring::find_first_of_(data_, size_, A{ch}, pos, 1u);
2362 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
2363 * Finds the first occurrence of any character not in `that` in this string.
2364 * \note Equivalent to `find_first_not_of(that.data(), 0, that.size())`
2366 template <std::size_t M>
2367 constexpr std::size_t find_first_not_of(
2368 const BasicFixedString<Char, M>& that) const noexcept {
2369 return find_first_not_of(that, 0u);
2372 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
2373 * Finds the first occurrence of any character not in `that` in this string.
2374 * \note Equivalent to `find_first_not_of(that.data(), 0, that.size())`
2376 template <std::size_t M>
2377 constexpr std::size_t find_first_not_of(
2378 const BasicFixedString<Char, M>& that,
2379 std::size_t pos) const noexcept(false) {
2380 return size_ == detail::fixedstring::checkOverflow(pos, size_)
2382 : detail::fixedstring::find_first_not_of_(
2383 data_, size_, that.data_, pos, that.size_);
2387 * Finds the first occurrence of any character not in the null-terminated
2388 * character sequence pointed to by `that` in this string.
2389 * \note Equivalent to `find_first_not_of(that, 0, strlen(that))`
2391 constexpr std::size_t find_first_not_of(const Char* that) const noexcept {
2392 return find_first_not_of(that, 0u, folly::constexpr_strlen(that));
2396 * Finds the first occurrence of any character not in the null-terminated
2397 * character sequence pointed to by `that` in this string,
2398 * starting at offset `pos`
2399 * \note Equivalent to `find_first_not_of(that, pos, strlen(that))`
2401 constexpr std::size_t find_first_not_of(const Char* that, std::size_t pos)
2402 const noexcept(false) {
2403 return find_first_not_of(that, pos, folly::constexpr_strlen(that));
2407 * Finds the first occurrence of any character not in the first `count`
2408 * characters in the buffer pointed to by `that` in this string, starting at
2410 * \pre `pos <= size()`
2411 * \pre `that` points to a buffer containing at least `count` contiguous
2413 * \return The smallest offset `i` such that `i >= pos` and
2414 * `std::find(that, that+count, at(i)) == that+count`; or
2415 * `npos` if there is no such offset `i`.
2416 * \throw std::out_of_range when `pos > size()`
2418 constexpr std::size_t find_first_not_of(
2421 std::size_t count) const noexcept(false) {
2422 return size_ == detail::fixedstring::checkOverflow(pos, size_)
2424 : detail::fixedstring::find_first_not_of_(
2425 data_, size_, that, pos, count);
2429 * Finds the first occurrence of any character other than `ch` in this string.
2430 * \note Equivalent to `find_first_not_of(&ch, 0, 1)`
2432 constexpr std::size_t find_first_not_of(Char ch) const noexcept {
2433 return find_first_not_of(ch, 0u);
2437 * Finds the first occurrence of any character other than `ch` in this string,
2438 * starting at offset `pos`.
2439 * \note Equivalent to `find_first_not_of(&ch, pos, 1)`
2441 constexpr std::size_t find_first_not_of(Char ch, std::size_t pos) const
2443 using A = const Char[1u];
2444 return 1u <= size_ - detail::fixedstring::checkOverflow(pos, size_)
2445 ? detail::fixedstring::find_first_not_of_(data_, size_, A{ch}, pos, 1u)
2449 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
2450 * Finds the last occurrence of any character in `that` in this string.
2451 * \note Equivalent to `find_last_of(that.data(), size(), that.size())`
2453 template <std::size_t M>
2454 constexpr std::size_t find_last_of(
2455 const BasicFixedString<Char, M>& that) const noexcept {
2456 return find_last_of(that, size_);
2460 * Finds the last occurrence of any character in `that` in this string,
2461 * starting at offset `pos`
2462 * \note Equivalent to `find_last_of(that.data(), pos, that.size())`
2464 template <std::size_t M>
2465 constexpr std::size_t find_last_of(
2466 const BasicFixedString<Char, M>& that,
2467 std::size_t pos) const noexcept(false) {
2470 : detail::fixedstring::find_last_of_(
2473 folly::constexpr_min(
2474 detail::fixedstring::checkOverflow(pos, size_), size_ - 1u),
2479 * Finds the last occurrence of any character in the null-terminated
2480 * character sequence pointed to by `that` in this string.
2481 * \note Equivalent to `find_last_of(that, size(), strlen(that))`
2483 constexpr std::size_t find_last_of(const Char* that) const noexcept {
2484 return find_last_of(that, size_, folly::constexpr_strlen(that));
2488 * Finds the last occurrence of any character in the null-terminated
2489 * character sequence pointed to by `that` in this string,
2490 * starting at offset `pos`
2491 * \note Equivalent to `find_last_of(that, pos, strlen(that))`
2493 constexpr std::size_t find_last_of(const Char* that, std::size_t pos) const
2495 return find_last_of(that, pos, folly::constexpr_strlen(that));
2499 * Finds the last occurrence of any character in the first `count` characters
2500 * in the buffer pointed to by `that` in this string, starting at offset
2502 * \pre `pos <= size()`
2503 * \pre `that` points to a buffer containing at least `count` contiguous
2505 * \return The largest offset `i` such that `i <= pos` and
2506 * `i < size()` and `std::find(that, that+count, at(i)) != that+count`; or
2507 * `npos` if there is no such offset `i`.
2508 * \throw std::out_of_range when `pos > size()`
2510 constexpr std::size_t find_last_of(
2513 std::size_t count) const noexcept(false) {
2516 : detail::fixedstring::find_last_of_(
2519 folly::constexpr_min(
2520 detail::fixedstring::checkOverflow(pos, size_), size_ - 1u),
2525 * Finds the last occurrence of `ch` in this string.
2526 * \note Equivalent to `find_last_of(&ch, size(), 1)`
2528 constexpr std::size_t find_last_of(Char ch) const noexcept {
2529 return find_last_of(ch, size_);
2533 * Finds the last occurrence of `ch` in this string,
2534 * starting at offset `pos`.
2535 * \note Equivalent to `find_last_of(&ch, pos, 1)`
2537 constexpr std::size_t find_last_of(Char ch, std::size_t pos) const
2539 using A = const Char[1u];
2542 : detail::fixedstring::find_last_of_(
2545 folly::constexpr_min(
2546 detail::fixedstring::checkOverflow(pos, size_), size_ - 1u),
2550 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
2551 * Finds the last occurrence of any character not in `that` in this string.
2552 * \note Equivalent to `find_last_not_of(that.data(), size(), that.size())`
2554 template <std::size_t M>
2555 constexpr std::size_t find_last_not_of(
2556 const BasicFixedString<Char, M>& that) const noexcept {
2557 return find_last_not_of(that, size_);
2561 * Finds the last occurrence of any character not in `that` in this string,
2562 * starting at offset `pos`
2563 * \note Equivalent to `find_last_not_of(that.data(), pos, that.size())`
2565 template <std::size_t M>
2566 constexpr std::size_t find_last_not_of(
2567 const BasicFixedString<Char, M>& that,
2568 std::size_t pos) const noexcept(false) {
2571 : detail::fixedstring::find_last_not_of_(
2574 folly::constexpr_min(
2575 detail::fixedstring::checkOverflow(pos, size_), size_ - 1u),
2580 * Finds the last occurrence of any character not in the null-terminated
2581 * character sequence pointed to by `that` in this string.
2582 * \note Equivalent to `find_last_not_of(that, size(), strlen(that))`
2584 constexpr std::size_t find_last_not_of(const Char* that) const noexcept {
2585 return find_last_not_of(that, size_, folly::constexpr_strlen(that));
2589 * Finds the last occurrence of any character not in the null-terminated
2590 * character sequence pointed to by `that` in this string,
2591 * starting at offset `pos`
2592 * \note Equivalent to `find_last_not_of(that, pos, strlen(that))`
2594 constexpr std::size_t find_last_not_of(const Char* that, std::size_t pos)
2595 const noexcept(false) {
2596 return find_last_not_of(that, pos, folly::constexpr_strlen(that));
2600 * Finds the last occurrence of any character not in the first `count`
2601 * characters in the buffer pointed to by `that` in this string, starting at
2603 * \pre `pos <= size()`
2604 * \pre `that` points to a buffer containing at least `count` contiguous
2606 * \return The largest offset `i` such that `i <= pos` and
2607 * `i < size()` and `std::find(that, that+count, at(i)) == that+count`; or
2608 * `npos` if there is no such offset `i`.
2609 * \throw std::out_of_range when `pos > size()`
2611 constexpr std::size_t find_last_not_of(
2614 std::size_t count) const noexcept(false) {
2617 : detail::fixedstring::find_last_not_of_(
2620 folly::constexpr_min(
2621 detail::fixedstring::checkOverflow(pos, size_), size_ - 1u),
2626 * Finds the last occurrence of any character other than `ch` in this string.
2627 * \note Equivalent to `find_last_not_of(&ch, size(), 1)`
2629 constexpr std::size_t find_last_not_of(Char ch) const noexcept {
2630 return find_last_not_of(ch, size_);
2634 * Finds the last occurrence of any character other than `ch` in this string,
2635 * starting at offset `pos`.
2636 * \note Equivalent to `find_last_not_of(&ch, pos, 1)`
2638 constexpr std::size_t find_last_not_of(Char ch, std::size_t pos) const
2640 using A = const Char[1u];
2643 : detail::fixedstring::find_last_not_of_(
2646 folly::constexpr_min(
2647 detail::fixedstring::checkOverflow(pos, size_), size_ - 1u),
2651 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
2652 * Asymmetric relational operators
2654 friend constexpr bool operator==(
2656 const BasicFixedString& b) noexcept {
2657 return detail::fixedstring::equal_(
2658 a, folly::constexpr_strlen(a), b.data_, b.size_);
2664 friend constexpr bool operator==(
2665 const BasicFixedString& a,
2666 const Char* b) noexcept {
2673 friend constexpr bool operator==(
2674 Range<const Char*> a,
2675 const BasicFixedString& b) noexcept {
2676 return detail::fixedstring::equal_(a.begin(), a.size(), b.data_, b.size_);
2682 friend constexpr bool operator==(
2683 const BasicFixedString& a,
2684 Range<const Char*> b) noexcept {
2688 friend constexpr bool operator!=(
2690 const BasicFixedString& b) noexcept {
2697 friend constexpr bool operator!=(
2698 const BasicFixedString& a,
2699 const Char* b) noexcept {
2706 friend constexpr bool operator!=(
2707 Range<const Char*> a,
2708 const BasicFixedString& b) noexcept {
2715 friend constexpr bool operator!=(
2716 const BasicFixedString& a,
2717 Range<const Char*> b) noexcept {
2721 friend constexpr bool operator<(
2723 const BasicFixedString& b) noexcept {
2724 return detail::fixedstring::Cmp::LT ==
2725 detail::fixedstring::compare_(
2726 a, 0u, folly::constexpr_strlen(a), b.data_, 0u, b.size_);
2732 friend constexpr bool operator<(
2733 const BasicFixedString& a,
2734 const Char* b) noexcept {
2735 return detail::fixedstring::Cmp::LT ==
2736 detail::fixedstring::compare_(
2737 a.data_, 0u, a.size_, b, 0u, folly::constexpr_strlen(b));
2743 friend constexpr bool operator<(
2744 Range<const Char*> a,
2745 const BasicFixedString& b) noexcept {
2746 return detail::fixedstring::Cmp::LT ==
2747 detail::fixedstring::compare_(
2748 a.begin(), 0u, a.size(), b.data_, 0u, b.size_);
2754 friend constexpr bool operator<(
2755 const BasicFixedString& a,
2756 Range<const Char*> b) noexcept {
2757 return detail::fixedstring::Cmp::LT ==
2758 detail::fixedstring::compare_(
2759 a.data_, 0u, a.size_, b.begin(), 0u, b.size());
2762 friend constexpr bool operator>(
2764 const BasicFixedString& b) noexcept {
2771 friend constexpr bool operator>(
2772 const BasicFixedString& a,
2773 const Char* b) noexcept {
2780 friend constexpr bool operator>(
2781 Range<const Char*> a,
2782 const BasicFixedString& b) noexcept {
2789 friend constexpr bool operator>(
2790 const BasicFixedString& a,
2791 Range<const Char*> b) noexcept {
2795 friend constexpr bool operator<=(
2797 const BasicFixedString& b) noexcept {
2804 friend constexpr bool operator<=(
2805 const BasicFixedString& a,
2806 const Char* b) noexcept {
2813 friend constexpr bool operator<=(
2814 Range<const Char*> const& a,
2815 const BasicFixedString& b) noexcept {
2822 friend constexpr bool operator<=(
2823 const BasicFixedString& a,
2824 Range<const Char*> b) noexcept {
2828 friend constexpr bool operator>=(
2830 const BasicFixedString& b) noexcept {
2837 friend constexpr bool operator>=(
2838 const BasicFixedString& a,
2839 const Char* b) noexcept {
2846 friend constexpr bool operator>=(
2847 Range<const Char*> a,
2848 const BasicFixedString& b) noexcept {
2855 friend constexpr bool operator>=(
2856 const BasicFixedString& a,
2857 Range<const Char*> const& b) noexcept {
2861 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
2862 * Asymmetric concatenation
2864 template <std::size_t M>
2865 friend constexpr BasicFixedString<Char, N + M - 1u> operator+(
2867 const BasicFixedString& b) noexcept {
2868 return detail::fixedstring::Helper::concat_<Char>(
2869 detail::fixedstring::checkNullTerminated(a),
2873 folly::make_index_sequence<N + M - 1u>{});
2879 template <std::size_t M>
2880 friend constexpr BasicFixedString<Char, N + M - 1u> operator+(
2881 const BasicFixedString& a,
2882 const Char (&b)[M]) noexcept {
2883 return detail::fixedstring::Helper::concat_<Char>(
2886 detail::fixedstring::checkNullTerminated(b),
2888 folly::make_index_sequence<N + M - 1u>{});
2894 friend constexpr BasicFixedString<Char, N + 1u> operator+(
2896 const BasicFixedString& b) noexcept {
2897 using A = const Char[2u];
2898 return detail::fixedstring::Helper::concat_<Char>(
2903 folly::make_index_sequence<N + 1u>{});
2909 friend constexpr BasicFixedString<Char, N + 1u> operator+(
2910 const BasicFixedString& a,
2912 using A = const Char[2u];
2913 return detail::fixedstring::Helper::concat_<Char>(
2918 folly::make_index_sequence<N + 1u>{});
2922 template <class C, std::size_t N>
2923 inline std::basic_ostream<C>& operator<<(
2924 std::basic_ostream<C>& os,
2925 const BasicFixedString<C, N>& string) {
2926 using StreamSize = decltype(os.width());
2927 os.write(string.begin(), static_cast<StreamSize>(string.size()));
2931 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
2932 * Symmetric relational operators
2934 template <class Char, std::size_t A, std::size_t B>
2935 constexpr bool operator==(
2936 const BasicFixedString<Char, A>& a,
2937 const BasicFixedString<Char, B>& b) noexcept {
2938 return detail::fixedstring::equal_(
2939 detail::fixedstring::Helper::data_(a),
2941 detail::fixedstring::Helper::data_(b),
2945 template <class Char, std::size_t A, std::size_t B>
2946 constexpr bool operator!=(
2947 const BasicFixedString<Char, A>& a,
2948 const BasicFixedString<Char, B>& b) {
2952 template <class Char, std::size_t A, std::size_t B>
2953 constexpr bool operator<(
2954 const BasicFixedString<Char, A>& a,
2955 const BasicFixedString<Char, B>& b) noexcept {
2956 return detail::fixedstring::Cmp::LT ==
2957 detail::fixedstring::compare_(
2958 detail::fixedstring::Helper::data_(a),
2961 detail::fixedstring::Helper::data_(b),
2966 template <class Char, std::size_t A, std::size_t B>
2967 constexpr bool operator>(
2968 const BasicFixedString<Char, A>& a,
2969 const BasicFixedString<Char, B>& b) noexcept {
2973 template <class Char, std::size_t A, std::size_t B>
2974 constexpr bool operator<=(
2975 const BasicFixedString<Char, A>& a,
2976 const BasicFixedString<Char, B>& b) noexcept {
2980 template <class Char, std::size_t A, std::size_t B>
2981 constexpr bool operator>=(
2982 const BasicFixedString<Char, A>& a,
2983 const BasicFixedString<Char, B>& b) noexcept {
2987 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
2988 * Symmetric concatenation
2990 template <class Char, std::size_t N, std::size_t M>
2991 constexpr BasicFixedString<Char, N + M> operator+(
2992 const BasicFixedString<Char, N>& a,
2993 const BasicFixedString<Char, M>& b) noexcept {
2994 return detail::fixedstring::Helper::concat_<Char>(
2995 detail::fixedstring::Helper::data_(a),
2997 detail::fixedstring::Helper::data_(b),
2999 folly::make_index_sequence<N + M>{});
3002 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
3003 * Construct a `BasicFixedString` object from a null-terminated array of
3004 * characters. The capacity and size of the string will be equal to one less
3005 * than the size of the array.
3006 * \pre `a` contains no embedded null characters.
3007 * \pre `a[N-1] == Char(0)`
3008 * \post For a returned string `s`, `s[i]==a[i]` for every `i` in [`0`,`N-1`].
3010 template <class Char, std::size_t N>
3011 constexpr BasicFixedString<Char, N - 1u> makeFixedString(
3012 const Char (&a)[N]) noexcept {
3016 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
3019 template <class Char, std::size_t N>
3020 FOLLY_CPP14_CONSTEXPR void swap(
3021 BasicFixedString<Char, N>& a,
3022 BasicFixedString<Char, N>& b) noexcept {
3026 inline namespace literals {
3027 inline namespace string_literals {
3029 // "const std::size_t&" is so that folly::npos has the same address in every
3030 // translation unit. This is to avoid potential violations of the ODR.
3031 constexpr const std::size_t& npos = detail::fixedstring::FixedStringBase::npos;
3034 #if defined(__GNUC__)
3035 #pragma GCC diagnostic push
3036 #pragma GCC diagnostic ignored "-Wpragmas"
3037 #pragma GCC diagnostic ignored "-Wgnu-string-literal-operator-template"
3039 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** *
3040 * User-defined literals for creating FixedString objects from string literals
3041 * on the compilers that support it.
3046 * using namespace folly::string_literals;
3047 * constexpr auto hello = "hello world!"_fs;
3050 * \note This requires a GNU compiler extension
3051 * (-Wgnu-string-literal-operator-template) supported by clang and gcc,
3052 * proposed for standardization in
3053 * <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0424r0.pdf>.
3055 * For portable code, prefer the suffixes `_fs4`, `_fs8`, `_fs16`, `_fs32`,
3056 * `_fs64`, and `_fs128` for creating instances of types `FixedString<4>`,
3057 * `FixedString<8>`, `FixedString<16>`, etc.
3059 template <class Char, Char... Cs>
3060 constexpr BasicFixedString<Char, sizeof...(Cs)> operator"" _fs() noexcept {
3061 using A = const Char[sizeof...(Cs) + 1u];
3062 // The `+` in `+A{etc}` forces the array type to decay to a pointer
3063 return {+A{Cs..., Char(0)}, sizeof...(Cs)};
3066 #pragma GCC diagnostic pop
3069 #define FOLLY_DEFINE_FIXED_STRING_UDL(N) \
3070 constexpr FixedString<N> operator"" _fs##N( \
3071 const char* that, std::size_t count) noexcept(false) { \
3072 return {that, count}; \
3076 // Define UDLs _fs4, _fs8, _fs16, etc for FixedString<[4, 8, 16, ...]>
3077 FOLLY_DEFINE_FIXED_STRING_UDL(4)
3078 FOLLY_DEFINE_FIXED_STRING_UDL(8)
3079 FOLLY_DEFINE_FIXED_STRING_UDL(16)
3080 FOLLY_DEFINE_FIXED_STRING_UDL(32)
3081 FOLLY_DEFINE_FIXED_STRING_UDL(64)
3082 FOLLY_DEFINE_FIXED_STRING_UDL(128)
3084 #undef FOLLY_DEFINE_FIXED_STRING_UDL
3089 // // numeric conversions:
3090 // template <std::size_t N>
3091 // constexpr int stoi(const FixedString<N>& str, int base = 10);
3092 // template <std::size_t N>
3093 // constexpr unsigned stou(const FixedString<N>& str, int base = 10);
3094 // template <std::size_t N>
3095 // constexpr long stol(const FixedString<N>& str, int base = 10);
3096 // template <std::size_t N>
3097 // constexpr unsigned long stoul(const FixedString<N>& str, int base = 10;
3098 // template <std::size_t N>
3099 // constexpr long long stoll(const FixedString<N>& str, int base = 10);
3100 // template <std::size_t N>
3101 // constexpr unsigned long long stoull(const FixedString<N>& str,
3103 // template <std::size_t N>
3104 // constexpr float stof(const FixedString<N>& str);
3105 // template <std::size_t N>
3106 // constexpr double stod(const FixedString<N>& str);
3107 // template <std::size_t N>
3108 // constexpr long double stold(const FixedString<N>& str);
3109 // template <int val>
3110 // constexpr FixedString</*...*/> to_fixed_string_i() noexcept;
3111 // template <unsigned val>
3112 // constexpr FixedString</*...*/> to_fixed_string_u() noexcept;
3113 // template <long val>
3114 // constexpr FixedString</*...*/> to_fixed_string_l() noexcept;
3115 // template <unsigned long val>
3116 // constexpr FixedString</*...*/> to_fixed_string_ul() noexcept;
3117 // template <long long val>
3118 // constexpr FixedString</*...*/> to_fixed_string_ll() noexcept
3119 // template <unsigned long long val>
3120 // constexpr FixedString</*...*/> to_fixed_string_ull() noexcept;