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/Range.h>
32 #include <folly/Utility.h>
33 #include <folly/portability/BitsFunctexcept.h>
34 #include <folly/portability/Constexpr.h>
36 // Define FOLLY_USE_CPP14_CONSTEXPR to be true if the compiler's C++14
37 // constexpr support is "good enough".
38 #ifndef FOLLY_USE_CPP14_CONSTEXPR
39 #if defined(__clang__)
40 #define FOLLY_USE_CPP14_CONSTEXPR __cplusplus >= 201300L
41 #elif defined(__GNUC__)
42 #define FOLLY_USE_CPP14_CONSTEXPR __cplusplus >= 201304L
44 #define FOLLY_USE_CPP14_CONSTEXPR 0 // MSVC?
48 #if FOLLY_USE_CPP14_CONSTEXPR
49 #define FOLLY_CPP14_CONSTEXPR constexpr
51 #define FOLLY_CPP14_CONSTEXPR inline
56 template <class Char, std::size_t N>
57 class BasicFixedString;
59 template <std::size_t N>
60 using FixedString = BasicFixedString<char, N>;
63 namespace fixedstring {
65 // This is a template so that the class static npos can be defined in the
67 template <class = void>
68 struct FixedStringBase_ {
69 static constexpr std::size_t npos = static_cast<std::size_t>(-1);
73 constexpr std::size_t FixedStringBase_<Void>::npos;
75 using FixedStringBase = FixedStringBase_<>;
77 // Intentionally NOT constexpr. By making this not constexpr, we make
78 // checkOverflow below ill-formed in a constexpr context when the condition
79 // it's testing for fails. In this way, precondition violations are reported
80 // at compile-time instead of at runtime.
81 [[noreturn]] inline void assertOutOfBounds() {
82 assert(false && "Array index out of bounds in BasicFixedString");
83 std::__throw_out_of_range("Array index out of bounds in BasicFixedString");
86 constexpr std::size_t checkOverflow(std::size_t i, std::size_t max) {
87 return i <= max ? i : (assertOutOfBounds(), max);
90 constexpr std::size_t checkOverflowOrNpos(std::size_t i, std::size_t max) {
91 return i == FixedStringBase::npos
93 : (i <= max ? i : (assertOutOfBounds(), max));
96 // Intentionally NOT constexpr. See note above for assertOutOfBounds
97 [[noreturn]] inline void assertNotNullTerminated() noexcept {
100 "Non-null terminated string used to initialize a BasicFixedString");
101 std::terminate(); // Fail hard, fail fast.
104 // Parsing help for human readers: the following is a constexpr noexcept
105 // function that accepts a reference to an array as a parameter and returns
106 // a reference to the same array.
107 template <class Char, std::size_t N>
108 constexpr const Char (&checkNullTerminated(const Char (&a)[N]) noexcept)[N] {
109 // Strange decltype(a)(a) used to make MSVC happy.
110 return a[N - 1u] == Char(0)
112 // In Debug mode, guard against embedded nulls:
113 && N - 1u == folly::detail::constexpr_strlen_internal(a, 0u)
116 : (assertNotNullTerminated(), decltype(a)(a));
119 enum class Cmp : int { LT = -1, EQ = 0, GT = 1 };
121 // Rather annoyingly, GCC's -Warray-bounds warning issues false positives for
122 // this code. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61971
123 #if defined(__GNUC__) && !defined(__CLANG__) && __GNUC__ <= 4
124 #pragma GCC diagnostic push
125 #pragma GCC diagnostic ignored "-Warray-bounds"
128 template <class Left, class Right>
129 constexpr Cmp compare_(
131 std::size_t left_pos,
132 std::size_t left_size,
134 std::size_t right_pos,
135 std::size_t right_size) noexcept {
136 return left_pos == left_size
137 ? (right_pos == right_size ? Cmp::EQ : Cmp::LT)
138 : (right_pos == right_size ? Cmp::GT
139 : (left[left_pos] < right[right_pos]
141 : (left[left_pos] > right[right_pos]
143 : fixedstring::compare_(
152 template <class Left, class Right>
153 constexpr bool equal_(
155 std::size_t left_size,
157 std::size_t right_size) noexcept {
158 return left_size == right_size &&
159 Cmp::EQ == compare_(left, 0u, left_size, right, 0u, right_size);
162 template <class Char, class Left, class Right>
163 constexpr Char char_at_(
165 std::size_t left_count,
167 std::size_t right_count,
168 std::size_t i) noexcept {
169 return i < left_count
171 : i < (left_count + right_count) ? right[i - left_count] : Char(0);
174 template <class Char, class Left, class Right>
175 constexpr Char char_at_(
177 std::size_t left_size,
178 std::size_t left_pos,
179 std::size_t left_count,
181 std::size_t right_pos,
182 std::size_t right_count,
183 std::size_t i) noexcept {
186 : (i < right_count + left_pos ? right[i - left_pos + right_pos]
187 : (i < left_size - left_count + right_count
188 ? left[i - right_count + left_count]
192 template <class Left, class Right>
193 constexpr bool find_at_(
197 std::size_t count) noexcept {
198 return 0u == count || (left[pos + count - 1u] == right[count - 1u] &&
199 find_at_(left, right, pos, count - 1u));
202 template <class Char, class Right>
204 find_one_of_at_(Char ch, const Right& right, std::size_t pos) noexcept {
206 (ch == right[pos - 1u] || find_one_of_at_(ch, right, pos - 1u));
209 template <class Left, class Right>
210 constexpr std::size_t find_(
212 std::size_t left_size,
215 std::size_t count) noexcept {
216 return find_at_(left, right, pos, count) ? pos
217 : left_size <= pos + count
218 ? FixedStringBase::npos
219 : find_(left, left_size, right, pos + 1u, count);
222 template <class Left, class Right>
223 constexpr std::size_t rfind_(
227 std::size_t count) noexcept {
228 return find_at_(left, right, pos, count)
230 : 0u == pos ? FixedStringBase::npos
231 : rfind_(left, right, pos - 1u, count);
234 template <class Left, class Right>
235 constexpr std::size_t find_first_of_(
237 std::size_t left_size,
240 std::size_t count) noexcept {
241 return find_one_of_at_(left[pos], right, count) ? pos
242 : left_size <= pos + 1u
243 ? FixedStringBase::npos
244 : find_first_of_(left, left_size, right, pos + 1u, count);
247 template <class Left, class Right>
248 constexpr std::size_t find_first_not_of_(
250 std::size_t left_size,
253 std::size_t count) noexcept {
254 return !find_one_of_at_(left[pos], right, count) ? pos
255 : left_size <= pos + 1u
256 ? FixedStringBase::npos
257 : find_first_not_of_(left, left_size, right, pos + 1u, count);
260 template <class Left, class Right>
261 constexpr std::size_t find_last_of_(
265 std::size_t count) noexcept {
266 return find_one_of_at_(left[pos], right, count)
268 : 0u == pos ? FixedStringBase::npos
269 : find_last_of_(left, right, pos - 1u, count);
272 template <class Left, class Right>
273 constexpr std::size_t find_last_not_of_(
277 std::size_t count) noexcept {
278 return !find_one_of_at_(left[pos], right, count)
280 : 0u == pos ? FixedStringBase::npos
281 : find_last_not_of_(left, right, pos - 1u, count);
285 template <class Char, class Left, class Right, std::size_t... Is>
286 static constexpr BasicFixedString<Char, sizeof...(Is)> concat_(
288 std::size_t left_count,
290 std::size_t right_count,
291 folly::index_sequence<Is...> is) noexcept {
292 return {left, left_count, right, right_count, is};
295 template <class Char, class Left, class Right, std::size_t... Is>
296 static constexpr BasicFixedString<Char, sizeof...(Is)> replace_(
298 std::size_t left_size,
299 std::size_t left_pos,
300 std::size_t left_count,
302 std::size_t right_pos,
303 std::size_t right_count,
304 folly::index_sequence<Is...> is) noexcept {
315 template <class Char, std::size_t N>
316 static constexpr const Char (
317 &data_(const BasicFixedString<Char, N>& that) noexcept)[N + 1u] {
322 #if defined(__GNUC__) && !defined(__CLANG__) && __GNUC__ <= 4
323 #pragma GCC diagnostic pop
327 FOLLY_CPP14_CONSTEXPR void constexpr_swap(T& a, T& b) noexcept(
328 noexcept(a = T(std::move(a)))) {
329 T tmp((std::move(a)));
334 // FUTURE: use const_log2 to fold instantiations of BasicFixedString together.
335 // All BasicFixedString<C, N> instantiations could share the implementation
336 // of BasicFixedString<C, M>, where M is the next highest power of 2 after N.
338 // Also, because of alignment of the data_ and size_ members, N should never be
339 // smaller than `(alignof(std::size_t)/sizeof(C))-1` (-1 because of the null
340 // terminator). OR, create a specialization for BasicFixedString<C, 0u> that
341 // does not have a size_ member, since it is unnecessary.
342 constexpr std::size_t const_log2(std::size_t N, std::size_t log2 = 0u) {
343 return N / 2u == 0u ? log2 : const_log2(N / 2u, log2 + 1u);
346 // For constexpr reverse iteration over a BasicFixedString
348 struct ReverseIterator {
354 using other = typename std::conditional<
355 std::is_const<T>::value,
356 ReverseIterator<typename std::remove_const<T>::type>,
360 using value_type = typename std::remove_const<T>::type;
361 using reference = T&;
363 using difference_type = std::ptrdiff_t;
364 using iterator_category = std::random_access_iterator_tag;
366 constexpr ReverseIterator() = default;
367 constexpr ReverseIterator(const ReverseIterator&) = default;
368 FOLLY_CPP14_CONSTEXPR ReverseIterator& operator=(const ReverseIterator&) =
370 constexpr explicit ReverseIterator(T* p) noexcept : p_(p) {}
371 constexpr /* implicit */ ReverseIterator(const other& that) noexcept
373 friend constexpr bool operator==(
375 ReverseIterator b) noexcept {
378 friend constexpr bool operator!=(
380 ReverseIterator b) noexcept {
383 constexpr reference operator*() const {
386 FOLLY_CPP14_CONSTEXPR ReverseIterator& operator++() noexcept {
390 FOLLY_CPP14_CONSTEXPR ReverseIterator operator++(int)noexcept {
395 FOLLY_CPP14_CONSTEXPR ReverseIterator& operator--() noexcept {
399 FOLLY_CPP14_CONSTEXPR ReverseIterator operator--(int)noexcept {
404 FOLLY_CPP14_CONSTEXPR ReverseIterator& operator+=(std::ptrdiff_t i) noexcept {
408 friend constexpr ReverseIterator operator+(
410 ReverseIterator that) noexcept {
411 return ReverseIterator{that.p_ - i};
413 friend constexpr ReverseIterator operator+(
414 ReverseIterator that,
415 std::ptrdiff_t i) noexcept {
416 return ReverseIterator{that.p_ - i};
418 FOLLY_CPP14_CONSTEXPR ReverseIterator& operator-=(std::ptrdiff_t i) noexcept {
422 friend constexpr ReverseIterator operator-(
423 ReverseIterator that,
424 std::ptrdiff_t i) noexcept {
425 return ReverseIterator{that.p_ + i};
427 friend constexpr std::ptrdiff_t operator-(
429 ReverseIterator b) noexcept {
432 constexpr reference operator[](std::ptrdiff_t i) const noexcept {
437 } // namespace fixedstring
438 } // namespace detail
440 // Defined in folly/Hash.h
441 std::uint32_t hsieh_hash32_buf(const void* buf, std::size_t len);
443 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** *
444 * \class BasicFixedString
446 * \tparam Char The character type. Must be a scalar type.
447 * \tparam N The capacity and max size of string instances of this type.
449 * \brief A class for holding up to `N` characters of type `Char` that is
450 * amenable to `constexpr` string manipulation. It is guaranteed to not
451 * perform any dynamic allocation.
453 * `BasicFixedString` is a `std::string` work-alike that stores characters in an
454 * internal buffer. It has minor interface differences that make it easy to work
455 * with strings in a `constexpr` context.
460 * constexpr auto hello = makeFixedString("hello"); // a FixedString<5>
461 * constexpr auto world = makeFixedString("world"); // a FixedString<5>
462 * constexpr auto hello_world = hello + ' ' + world + '!'; // a FixedString<12>
463 * static_assert(hello_world == "hello world!", "neato!");
466 * `FixedString<N>` is an alias for `BasicFixedString<char, N>`.
468 * \par Constexpr and In-place Mutation
470 * On a C++14 compiler, `BasicFixedString` supports the full `std::string`
471 * interface as `constexpr` member functions. On a C++11 compiler, the mutating
472 * members are not `constexpr`, but non-mutating alternatives, which create a
473 * new string, can be used instead. For example, instead of this:
476 * constexpr FixedString<10> replace_example_cpp14() {
477 * FixedString<10> test{"****"};
478 * test.replace(1, 2, "!!!!");
479 * return test; // returns "*!!!!*"
483 * You might write this instead:
486 * constexpr FixedString<10> replace_example_cpp11() {
487 * // GNU compilers have an extension that make it possible to create
488 * // FixedString objects with a `""_fs` user-defined literal.
489 * using namespace folly;
490 * return makeFixedString("****").creplace(1, 2, "!!!!"); // "*!!!!*"
494 * \par User-defined Literals
495 * Instead of using the `folly::makeFixedString` helper function, you can use
496 * a user-defined literal to make `FixedString` instances. The UDL feature of
497 * C++ has some limitations that make this less than ideal; you must tell the
498 * compiler roughly how many characters are in the string. The suffixes `_fs4`,
499 * `_fs8`, `_fs16`, `_fs32`, `_fs64`, and `_fs128` exist to create instances
500 * of types `FixedString<4>`, `FixedString<8>`, etc. For example:
503 * using namespace folly::string_literals;
504 * constexpr auto hello = "hello"_fs8; // A FixedString<8> containing "hello"
507 * See Error Handling below for what to expect when you try to exceed the
508 * capacity of a `FixedString` by storing too many characters in it.
510 * If your compiler supports GNU extensions, there is one additional suffix you
511 * can use: `_fs`. This suffix always creates `FixedString` objects of exactly
512 * the right size. For example:
515 * using namespace folly::string_literals;
516 * // NOTE: Only works on compilers with GNU extensions enabled. Clang and
517 * // gcc support this (-Wgnu-string-literal-operator-template):
518 * constexpr auto hello = "hello"_fs; // A FixedString<5> containing "hello"
521 * \par Error Handling:
522 * The capacity of a `BasicFixedString` is set at compile time. When the user
523 * asks the string to exceed its capacity, one of three things will happen,
524 * depending on the context:
526 * -# If the attempt is made while evaluating a constant expression, the
527 * program will fail to compile.
528 * -# Otherwise, if the program is being run in debug mode, it will `assert`.
529 * -# Otherwise, the failed operation will throw a `std::out_of_range`
532 * This is also the case if an invalid offset is passed to any member function,
533 * or if `pop_back` or `cpop_back` is called on an empty `BasicFixedString`.
535 * Member functions documented as having preconditions will assert in Debug
536 * mode (`!defined(NDEBUG)`) on precondition failures. Those documented with
537 * \b Throws clauses will throw the specified exception on failure. Those with
538 * both a precondition and a \b Throws clause will assert in Debug and throw
541 template <class Char, std::size_t N>
542 class BasicFixedString : private detail::fixedstring::FixedStringBase {
544 template <class, std::size_t>
545 friend class BasicFixedString;
546 friend struct detail::fixedstring::Helper;
548 Char data_[N + 1u]; // +1 for the null terminator
549 std::size_t size_; // Nbr of chars, not incl. null terminator. size_ <= N.
551 using Indices = folly::make_index_sequence<N>;
553 template <class That, std::size_t... Is>
554 constexpr BasicFixedString(
557 folly::index_sequence<Is...>,
559 std::size_t count = npos) noexcept
560 : data_{(Is < (size - pos) && Is < count ? that[Is + pos] : Char(0))...,
562 size_{folly::constexpr_min(size - pos, count)} {}
564 template <std::size_t... Is>
565 constexpr BasicFixedString(
568 folly::index_sequence<Is...>) noexcept
569 : data_{((Is < count) ? ch : Char(0))..., Char(0)}, size_{count} {}
571 // Concatenation constructor
572 template <class Left, class Right, std::size_t... Is>
573 constexpr BasicFixedString(
575 std::size_t left_size,
577 std::size_t right_size,
578 folly::index_sequence<Is...>) noexcept
579 : data_{detail::fixedstring::char_at_<Char>(
586 size_{left_size + right_size} {}
588 // Replace constructor
589 template <class Left, class Right, std::size_t... Is>
590 constexpr BasicFixedString(
592 std::size_t left_size,
593 std::size_t left_pos,
594 std::size_t left_count,
596 std::size_t right_pos,
597 std::size_t right_count,
598 folly::index_sequence<Is...>) noexcept
599 : data_{detail::fixedstring::char_at_<Char>(
609 size_{left_size - left_count + right_count} {}
612 using size_type = std::size_t;
613 using difference_type = std::ptrdiff_t;
614 using reference = Char&;
615 using const_reference = const Char&;
616 using pointer = Char*;
617 using const_pointer = const Char*;
618 using iterator = Char*;
619 using const_iterator = const Char*;
620 using reverse_iterator = detail::fixedstring::ReverseIterator<Char>;
621 using const_reverse_iterator =
622 detail::fixedstring::ReverseIterator<const Char>;
624 using detail::fixedstring::FixedStringBase::npos;
626 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
628 * \post `size() == 0`
629 * \post `at(0) == Char(0)`
631 constexpr BasicFixedString() : data_{}, size_{} {}
633 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
635 * \post `size() == that.size()`
636 * \post `0 == strncmp(data(), that.data(), size())`
637 * \post `at(size()) == Char(0)`
639 constexpr BasicFixedString(const BasicFixedString& /*that*/) = default;
641 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
642 * Construct from a differently-sized BasicFixedString
643 * \pre `that.size() <= N`
644 * \post `size() == that.size()`
645 * \post `0 == strncmp(data(), that.data(), size())`
646 * \post `at(size()) == Char(0)`
647 * \throw std::out_of_range when that.size() > N. When M <= N, this
648 * constructor will never throw.
649 * \note Conversions from larger-capacity BasicFixedString objects to smaller
650 * ones (`M > N`) are allowed as long as the *size()* of the source string
653 template <std::size_t M>
654 constexpr /* implicit */ BasicFixedString(
655 const BasicFixedString<Char, M>& that) noexcept(M <= N)
656 : BasicFixedString{that, 0u, that.size_} {}
658 // Why is this deleted? To avoid confusion with the constructor that takes
659 // a const Char* and a count.
660 template <std::size_t M>
661 constexpr BasicFixedString(
662 const BasicFixedString<Char, M>& that,
663 std::size_t pos) noexcept(false) = delete;
665 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
666 * Construct from an BasicFixedString, an offset, and a count
667 * \param that The source string
668 * \param pos The starting position in `that`
669 * \param count The number of characters to copy. If `npos`, `count` is taken
670 * to be `that.size()-pos`.
671 * \pre `pos <= that.size()`
672 * \pre `count <= that.size()-pos && count <= N`
673 * \post `size() == count`
674 * \post `0 == strncmp(data(), that.data()+pos, size())`
675 * \post `at(size()) == Char(0)`
676 * \throw std::out_of_range when pos+count > that.size(), or when
679 template <std::size_t M>
680 constexpr BasicFixedString(
681 const BasicFixedString<Char, M>& that,
683 std::size_t count) noexcept(false)
687 folly::make_index_sequence<(M < N ? M : N)>{},
689 detail::fixedstring::checkOverflow(
690 detail::fixedstring::checkOverflowOrNpos(
693 detail::fixedstring::checkOverflow(pos, that.size_)),
696 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
697 * Construct from a string literal
699 * \pre `that[M-1] == Char(0)`
700 * \post `0 == strncmp(data(), that, M-1)`
701 * \post `size() == M-1`
702 * \post `at(size()) == Char(0)`
704 template <std::size_t M, class = typename std::enable_if<(M - 1u <= N)>::type>
705 constexpr /* implicit */ BasicFixedString(const Char (&that)[M]) noexcept
706 : BasicFixedString{detail::fixedstring::checkNullTerminated(that),
708 folly::make_index_sequence<M - 1u>{}} {}
710 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
711 * Construct from a `const Char*` and count
712 * \pre `that` points to an array of at least `count` characters.
714 * \post `size() == count`
715 * \post `0 == strncmp(data(), that, size())`
716 * \post `at(size()) == Char(0)`
717 * \throw std::out_of_range when count > N
719 constexpr BasicFixedString(const Char* that, std::size_t count) noexcept(
721 : BasicFixedString{that,
722 detail::fixedstring::checkOverflow(count, N),
725 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
726 * Construct an BasicFixedString that contains `count` characters, all
729 * \post `size() == count`
730 * \post `npos == find_first_not_of(ch)`
731 * \post `at(size()) == Char(0)`
732 * \throw std::out_of_range when count > N
734 constexpr BasicFixedString(std::size_t count, Char ch) noexcept(false)
735 : BasicFixedString{detail::fixedstring::checkOverflow(count, N),
739 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
740 * Construct an BasicFixedString from a `std::initializer_list` of
742 * \pre `il.size() <= N`
743 * \post `size() == count`
744 * \post `0 == strncmp(data(), il.begin(), size())`
745 * \post `at(size()) == Char(0)`
746 * \throw std::out_of_range when il.size() > N
748 constexpr BasicFixedString(std::initializer_list<Char> il) noexcept(false)
749 : BasicFixedString{il.begin(), il.size()} {}
751 FOLLY_CPP14_CONSTEXPR BasicFixedString& operator=(
752 const BasicFixedString&) noexcept = default;
754 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
755 * Assign from a `BasicFixedString<Char, M>`.
756 * \pre `that.size() <= N`
757 * \post `size() == that.size()`
758 * \post `0 == strncmp(data(), that.begin(), size())`
759 * \post `at(size()) == Char(0)`
760 * \throw std::out_of_range when that.size() > N. When M <= N, this
761 * assignment operator will never throw.
762 * \note Assignments from larger-capacity BasicFixedString objects to smaller
763 * ones (`M > N`) are allowed as long as the *size* of the source string is
767 template <std::size_t M>
768 FOLLY_CPP14_CONSTEXPR BasicFixedString& operator=(
769 const BasicFixedString<Char, M>& that) noexcept(M <= N) {
770 detail::fixedstring::checkOverflow(that.size_, N);
771 size_ = that.copy(data_, that.size_);
772 data_[size_] = Char(0);
776 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
777 * Assign from a null-terminated array of characters.
779 * \pre `that` has no embedded null characters
780 * \pre `that[M-1]==Char(0)`
781 * \post `size() == M-1`
782 * \post `0 == strncmp(data(), that, size())`
783 * \post `at(size()) == Char(0)`
786 template <std::size_t M, class = typename std::enable_if<(M - 1u <= N)>::type>
787 FOLLY_CPP14_CONSTEXPR BasicFixedString& operator=(
788 const Char (&that)[M]) noexcept {
789 return assign(detail::fixedstring::checkNullTerminated(that), M - 1u);
792 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
793 * Assign from an `initializer_list` of characters.
794 * \pre `il.size() <= N`
795 * \post `size() == il.size()`
796 * \post `0 == strncmp(data(), il.begin(), size())`
797 * \post `at(size()) == Char(0)`
798 * \throw std::out_of_range when il.size() > N
801 FOLLY_CPP14_CONSTEXPR BasicFixedString& operator=(
802 std::initializer_list<Char> il) noexcept(false) {
803 detail::fixedstring::checkOverflow(il.size(), N);
804 for (std::size_t i = 0u; i < il.size(); ++i) {
805 data_[i] = il.begin()[i];
808 data_[size_] = Char(0);
812 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
813 * Conversion to folly::Range
814 * \return `Range<Iter>{begin(), end()}`
818 class = typename std::enable_if<
819 std::is_convertible<Char*, Iter>::value>::type>
820 FOLLY_CPP14_CONSTEXPR /* implicit */ operator Range<Iter>() noexcept {
821 return {begin(), end()};
829 class = typename std::enable_if<
830 std::is_convertible<const Char*, Iter>::value>::type>
831 constexpr /* implicit */ operator Range<Iter>() const noexcept {
832 return {begin(), end()};
835 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
836 * Conversion to folly::Range
837 * \return `Range<Char*>{begin(), end()}`
839 FOLLY_CPP14_CONSTEXPR Range<Char*> toRange() noexcept {
840 return {begin(), end()};
846 constexpr Range<const Char*> toRange() const noexcept {
847 return {begin(), end()};
850 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
851 * Conversion to std::basic_string<Char>
852 * \return `std::basic_string<Char>{begin(), end()}`
854 /* implicit */ operator std::basic_string<Char>() const noexcept(false) {
855 return std::basic_string<Char>{begin(), end()};
858 std::basic_string<Char> toStdString() const noexcept(false) {
859 return std::basic_string<Char>{begin(), end()};
862 // Think hard about whether this is a good idea. It's certainly better than
863 // an implicit conversion to `const Char*` since `delete "hi"_fs` will fail
864 // to compile. But it creates ambiguities when passing a FixedString to an
865 // API that has overloads for `const char*` and `folly::Range`, for instance.
866 // using ArrayType = Char[N];
867 // FOLLY_CPP14_CONSTEXPR /* implicit */ operator ArrayType&() noexcept {
871 // using ConstArrayType = const Char[N];
872 // constexpr /* implicit */ operator ConstArrayType&() const noexcept {
876 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
877 * Assigns a sequence of `count` characters of value `ch`.
878 * \param count The count of characters.
881 * \post `size() == count`
882 * \post `npos == find_first_not_of(ch)`
883 * \post `at(size()) == Char(0)`
884 * \throw std::out_of_range when count > N
887 FOLLY_CPP14_CONSTEXPR BasicFixedString& assign(
889 Char ch) noexcept(false) {
890 detail::fixedstring::checkOverflow(count, N);
891 for (std::size_t i = 0u; i < count; ++i) {
895 data_[size_] = Char(0);
899 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
900 * Assigns characters from an `BasicFixedString` to this object.
901 * \note Equivalent to `assign(that, 0, that.size())`
903 template <std::size_t M>
904 FOLLY_CPP14_CONSTEXPR BasicFixedString& assign(
905 const BasicFixedString<Char, M>& that) noexcept(M <= N) {
909 // Why is this overload deleted? So users aren't confused by the difference
910 // between str.assign("foo", N) and str.assign("foo"_fs, N). In the former,
911 // N is a count of characters. In the latter, it would be a position, which
912 // totally changes the meaning of the code.
913 template <std::size_t M>
914 FOLLY_CPP14_CONSTEXPR BasicFixedString& assign(
915 const BasicFixedString<Char, M>& that,
916 std::size_t pos) noexcept(false) = delete;
918 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
919 * Assigns `count` characters from an `BasicFixedString` to this object,
920 * starting at position `pos` in the source object.
921 * \param that The source string.
922 * \param pos The starting position in the source string.
923 * \param count The number of characters to copy. If `npos`, `count` is taken
924 * to be `that.size()-pos`.
925 * \pre `pos <= that.size()`
926 * \pre `count <= that.size()-pos`
928 * \post `size() == count`
929 * \post `0 == strncmp(data(), that.begin() + pos, count)`
930 * \post `at(size()) == Char(0)`
931 * \throw std::out_of_range when pos > that.size() or count > that.size()-pos
935 template <std::size_t M>
936 FOLLY_CPP14_CONSTEXPR BasicFixedString& assign(
937 const BasicFixedString<Char, M>& that,
939 std::size_t count) noexcept(false) {
940 detail::fixedstring::checkOverflow(pos, that.size_);
943 detail::fixedstring::checkOverflowOrNpos(count, that.size_ - pos));
946 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
947 * Assigns characters from an `BasicFixedString` to this object.
948 * \pre `that` contains no embedded nulls.
949 * \pre `that[M-1] == Char(0)`
950 * \note Equivalent to `assign(that, M - 1)`
952 template <std::size_t M, class = typename std::enable_if<(M - 1u <= N)>::type>
953 FOLLY_CPP14_CONSTEXPR BasicFixedString& assign(
954 const Char (&that)[M]) noexcept {
955 return assign(detail::fixedstring::checkNullTerminated(that), M - 1u);
958 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
959 * Assigns `count` characters from a range of characters to this object.
960 * \param that A pointer to a range of characters.
961 * \param count The number of characters to copy.
962 * \pre `that` points to at least `count` characters.
964 * \post `size() == count`
965 * \post `0 == strncmp(data(), that, count)`
966 * \post `at(size()) == Char(0)`
967 * \throw std::out_of_range when count > N
970 FOLLY_CPP14_CONSTEXPR BasicFixedString& assign(
972 std::size_t count) noexcept(false) {
973 detail::fixedstring::checkOverflow(count, N);
974 for (std::size_t i = 0u; i < count; ++i) {
978 data_[size_] = Char(0);
982 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
983 * Swap the contents of this string with `that`.
985 FOLLY_CPP14_CONSTEXPR void swap(BasicFixedString& that) noexcept {
986 // less-than-or-equal here to copy the null terminator:
987 for (std::size_t i = 0u; i <= folly::constexpr_max(size_, that.size_);
989 detail::fixedstring::constexpr_swap(data_[i], that.data_[i]);
991 detail::fixedstring::constexpr_swap(size_, that.size_);
994 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
995 * Return a pointer to a range of `size()+1` characters, the last of which
998 FOLLY_CPP14_CONSTEXPR Char* data() noexcept {
1005 constexpr const Char* data() const noexcept {
1009 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1012 constexpr const Char* c_str() const noexcept {
1016 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1019 FOLLY_CPP14_CONSTEXPR Char* begin() noexcept {
1026 constexpr const Char* begin() const noexcept {
1030 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1033 constexpr const Char* cbegin() const noexcept {
1037 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1038 * \return `data() + size()`.
1040 FOLLY_CPP14_CONSTEXPR Char* end() noexcept {
1041 return data_ + size_;
1047 constexpr const Char* end() const noexcept {
1048 return data_ + size_;
1051 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1052 * \return `data() + size()`.
1054 constexpr const Char* cend() const noexcept {
1058 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1059 * Returns a reverse iterator to the first character of the reversed string.
1060 * It corresponds to the last + 1 character of the non-reversed string.
1062 FOLLY_CPP14_CONSTEXPR reverse_iterator rbegin() noexcept {
1063 return reverse_iterator{data_ + size_};
1069 constexpr const_reverse_iterator rbegin() const noexcept {
1070 return const_reverse_iterator{data_ + size_};
1074 * \note Equivalent to `rbegin()` on a const-qualified reference to `*this`.
1076 constexpr const_reverse_iterator crbegin() const noexcept {
1080 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1081 * Returns a reverse iterator to the last + 1 character of the reversed
1082 * string. It corresponds to the first character of the non-reversed string.
1084 FOLLY_CPP14_CONSTEXPR reverse_iterator rend() noexcept {
1085 return reverse_iterator{data_};
1091 constexpr const_reverse_iterator rend() const noexcept {
1092 return const_reverse_iterator{data_};
1096 * \note Equivalent to `rend()` on a const-qualified reference to `*this`.
1098 constexpr const_reverse_iterator crend() const noexcept {
1103 * \return The number of `Char` elements in the string.
1105 constexpr std::size_t size() const noexcept {
1110 * \return The number of `Char` elements in the string.
1112 constexpr std::size_t length() const noexcept {
1117 * \return True if and only if `size() == 0`.
1119 constexpr bool empty() const noexcept {
1126 static constexpr std::size_t capacity() noexcept {
1133 static constexpr std::size_t max_size() noexcept {
1137 // We would need to reimplement folly::Hash to make this
1139 std::uint32_t hash() const noexcept {
1140 return folly::hsieh_hash32_buf(data_, size_);
1144 * \note `at(size())` is allowed will return `Char(0)`.
1145 * \return `*(data() + i)`
1146 * \throw std::out_of_range when i > size()
1148 FOLLY_CPP14_CONSTEXPR Char& at(std::size_t i) noexcept(false) {
1151 : (std::__throw_out_of_range("Out of range in BasicFixedString::at"),
1158 constexpr const Char& at(std::size_t i) const noexcept(false) {
1161 : (std::__throw_out_of_range("Out of range in BasicFixedString::at"),
1166 * \pre `i <= size()`
1167 * \note `(*this)[size()]` is allowed will return `Char(0)`.
1168 * \return `*(data() + i)`
1170 FOLLY_CPP14_CONSTEXPR Char& operator[](std::size_t i) noexcept {
1174 return data_[detail::fixedstring::checkOverflow(i, size_)];
1181 constexpr const Char& operator[](std::size_t i) const noexcept {
1185 return data_[detail::fixedstring::checkOverflow(i, size_)];
1190 * \note Equivalent to `(*this)[0]`
1192 FOLLY_CPP14_CONSTEXPR Char& front() noexcept {
1199 constexpr const Char& front() const noexcept {
1204 * \note Equivalent to `at(size()-1)`
1207 FOLLY_CPP14_CONSTEXPR Char& back() noexcept {
1209 return data_[size_ - 1u];
1211 return data_[size_ - detail::fixedstring::checkOverflow(1u, size_)];
1218 constexpr const Char& back() const noexcept {
1220 return data_[size_ - 1u];
1222 return data_[size_ - detail::fixedstring::checkOverflow(1u, size_)];
1227 * Clears the contents of this string.
1228 * \post `size() == 0u`
1229 * \post `at(size()) == Char(0)`
1231 FOLLY_CPP14_CONSTEXPR void clear() noexcept {
1232 data_[0u] = Char(0);
1237 * \note Equivalent to `append(1u, ch)`.
1239 FOLLY_CPP14_CONSTEXPR void push_back(Char ch) noexcept(false) {
1240 detail::fixedstring::checkOverflow(1u, N - size_);
1242 data_[++size_] = Char(0);
1246 * \note Equivalent to `cappend(1u, ch)`.
1248 constexpr BasicFixedString<Char, N + 1u> cpush_back(Char ch) const noexcept {
1253 * Removes the last character from the string.
1255 * \post `size()` is one fewer than before calling `pop_back()`.
1256 * \post `at(size()) == Char(0)`
1257 * \post The characters in the half-open range `[0,size()-1)` are unmodified.
1258 * \throw std::out_of_range if empty().
1260 FOLLY_CPP14_CONSTEXPR void pop_back() noexcept(false) {
1261 detail::fixedstring::checkOverflow(1u, size_);
1263 data_[size_] = Char(0);
1267 * Returns a new string with the first `size()-1` characters from this string.
1269 * \note Equivalent to `BasicFixedString<Char, N-1u>{*this, 0u, size()-1u}`
1270 * \throw std::out_of_range if empty().
1272 constexpr BasicFixedString<Char, N - 1u> cpop_back() const noexcept(false) {
1273 return {*this, 0u, size_ - detail::fixedstring::checkOverflow(1u, size_)};
1276 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1277 * Appends `count` copies of `ch` to this string.
1278 * \pre `count + old_size <= N`
1279 * \post The first `old_size` characters of the string are unmodified.
1280 * \post `size() == old_size + count`
1281 * \throw std::out_of_range if count > N - size().
1283 FOLLY_CPP14_CONSTEXPR BasicFixedString& append(
1285 Char ch) noexcept(false) {
1286 detail::fixedstring::checkOverflow(count, N - size_);
1287 for (std::size_t i = 0u; i < count; ++i)
1288 data_[size_ + i] = ch;
1290 data_[size_] = Char(0);
1295 * \note Equivalent to `append(*this, 0, that.size())`.
1297 template <std::size_t M>
1298 FOLLY_CPP14_CONSTEXPR BasicFixedString& append(
1299 const BasicFixedString<Char, M>& that) noexcept(false) {
1300 return append(that, 0u, that.size_);
1303 // Why is this overload deleted? So as not to get confused with
1304 // append("null-terminated", N), where N would be a count instead
1306 template <std::size_t M>
1307 FOLLY_CPP14_CONSTEXPR BasicFixedString& append(
1308 const BasicFixedString<Char, M>& that,
1309 std::size_t pos) noexcept(false) = delete;
1312 * Appends `count` characters from another string to this one, starting at a
1313 * given offset, `pos`.
1314 * \param that The source string.
1315 * \param pos The starting position in the source string.
1316 * \param count The number of characters to append. If `npos`, `count` is
1317 * taken to be `that.size()-pos`.
1318 * \pre `pos <= that.size()`
1319 * \pre `count <= that.size() - pos`
1320 * \pre `old_size + count <= N`
1321 * \post The first `old_size` characters of the string are unmodified.
1322 * \post `size() == old_size + count`
1323 * \post `at(size()) == Char(0)`
1324 * \throw std::out_of_range if pos + count > that.size() or if
1325 * `old_size + count > N`.
1327 template <std::size_t M>
1328 FOLLY_CPP14_CONSTEXPR BasicFixedString& append(
1329 const BasicFixedString<Char, M>& that,
1331 std::size_t count) noexcept(false) {
1332 detail::fixedstring::checkOverflow(pos, that.size_);
1333 count = detail::fixedstring::checkOverflowOrNpos(count, that.size_ - pos);
1334 detail::fixedstring::checkOverflow(count, N - size_);
1335 for (std::size_t i = 0u; i < count; ++i)
1336 data_[size_ + i] = that.data_[pos + i];
1338 data_[size_] = Char(0);
1343 * \note Equivalent to `append(that, strlen(that))`.
1345 FOLLY_CPP14_CONSTEXPR BasicFixedString& append(const Char* that) noexcept(
1347 return append(that, folly::constexpr_strlen(that));
1351 * Appends `count` characters from the specified character array.
1352 * \pre `that` points to a range of at least `count` characters.
1353 * \pre `count + old_size <= N`
1354 * \post The first `old_size` characters of the string are unmodified.
1355 * \post `size() == old_size + count`
1356 * \post `at(size()) == Char(0)`
1357 * \throw std::out_of_range if old_size + count > N.
1359 FOLLY_CPP14_CONSTEXPR BasicFixedString& append(
1361 std::size_t count) noexcept(false) {
1362 detail::fixedstring::checkOverflow(count, N - size_);
1363 for (std::size_t i = 0u; i < count; ++i)
1364 data_[size_ + i] = that[i];
1366 data_[size_] = Char(0);
1370 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1371 * Creates a new string by appending a character to an existing string, which
1372 * is left unmodified.
1373 * \note Equivalent to `*this + ch`
1375 constexpr BasicFixedString<Char, N + 1u> cappend(Char ch) const noexcept {
1380 * Creates a new string by appending a string to an existing string, which
1381 * is left unmodified.
1382 * \note Equivalent to `*this + ch`
1384 template <std::size_t M>
1385 constexpr BasicFixedString<Char, N + M> cappend(
1386 const BasicFixedString<Char, M>& that) const noexcept {
1387 return *this + that;
1390 // Deleted to avoid confusion with append("char*", N), where N is a count
1391 // instead of a position.
1392 template <std::size_t M>
1393 constexpr BasicFixedString<Char, N + M> cappend(
1394 const BasicFixedString<Char, M>& that,
1395 std::size_t pos) const noexcept(false) = delete;
1398 * Creates a new string by appending characters from one string to another,
1399 * which is left unmodified.
1400 * \note Equivalent to `*this + that.substr(pos, count)`
1402 template <std::size_t M>
1403 constexpr BasicFixedString<Char, N + M> cappend(
1404 const BasicFixedString<Char, M>& that,
1406 std::size_t count) const noexcept(false) {
1407 return creplace(size_, 0u, that, pos, count);
1411 * Creates a new string by appending a string literal to a string,
1412 * which is left unmodified.
1413 * \note Equivalent to `*this + that`
1415 template <std::size_t M>
1416 constexpr BasicFixedString<Char, N + M - 1u> cappend(
1417 const Char (&that)[M]) const noexcept {
1418 return creplace(size_, 0u, that);
1421 // Deleted to avoid confusion with append("char*", N), where N is a count
1422 // instead of a position
1423 template <std::size_t M>
1424 constexpr BasicFixedString<Char, N + M - 1u> cappend(
1425 const Char (&that)[M],
1426 std::size_t pos) const noexcept(false) = delete;
1429 * Creates a new string by appending characters from one string to another,
1430 * which is left unmodified.
1431 * \note Equivalent to `*this + makeFixedString(that).substr(pos, count)`
1433 template <std::size_t M>
1434 constexpr BasicFixedString<Char, N + M - 1u>
1435 cappend(const Char (&that)[M], std::size_t pos, std::size_t count) const
1437 return creplace(size_, 0u, that, pos, count);
1440 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1441 * Appends characters from a null-terminated string literal to this string.
1442 * \note Equivalent to `append(that)`.
1444 FOLLY_CPP14_CONSTEXPR BasicFixedString& operator+=(const Char* that) noexcept(
1446 return append(that);
1450 * Appends characters from another string to this one.
1451 * \note Equivalent to `append(that)`.
1453 template <std::size_t M>
1454 FOLLY_CPP14_CONSTEXPR BasicFixedString& operator+=(
1455 const BasicFixedString<Char, M>& that) noexcept(false) {
1456 return append(that, 0u, that.size_);
1460 * Appends a character to this string.
1461 * \note Equivalent to `push_back(ch)`.
1463 FOLLY_CPP14_CONSTEXPR BasicFixedString& operator+=(Char ch) noexcept(false) {
1469 * Appends characters from an `initializer_list` to this string.
1470 * \note Equivalent to `append(il.begin(), il.size())`.
1472 FOLLY_CPP14_CONSTEXPR BasicFixedString& operator+=(
1473 std::initializer_list<Char> il) noexcept(false) {
1474 return append(il.begin(), il.size());
1477 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1478 * Erase all characters from this string.
1479 * \note Equivalent to `clear()`
1482 FOLLY_CPP14_CONSTEXPR BasicFixedString& erase() noexcept {
1488 * Erases `count` characters from position `pos`. If `count` is `npos`,
1489 * erases from `pos` to the end of the string.
1490 * \pre `pos <= size()`
1491 * \pre `count <= size() - pos || count == npos`
1492 * \post `size() == old_size - min(count, old_size - pos)`
1493 * \post `at(size()) == Char(0)`
1495 * \throw std::out_of_range when pos > size().
1497 FOLLY_CPP14_CONSTEXPR BasicFixedString& erase(
1499 std::size_t count = npos) noexcept(false) {
1500 using A = const Char[1];
1503 detail::fixedstring::checkOverflowOrNpos(
1504 count, size_ - detail::fixedstring::checkOverflow(pos, size_)),
1510 * \note Equivalent to `erase(first - data(), 1)`
1511 * \return A pointer to the first character after the erased character.
1513 FOLLY_CPP14_CONSTEXPR Char* erase(const Char* first) noexcept(false) {
1514 erase(first - data_, 1u);
1515 return data_ + (first - data_);
1519 * \note Equivalent to `erase(first - data(), last - first)`
1520 * \return A pointer to the first character after the erased characters.
1522 FOLLY_CPP14_CONSTEXPR Char* erase(
1524 const Char* last) noexcept(false) {
1525 erase(first - data_, last - first);
1526 return data_ + (first - data_);
1529 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1530 * Create a new string by erasing all the characters from this string.
1531 * \note Equivalent to `BasicFixedString<Char, 0>{}`
1533 constexpr BasicFixedString<Char, 0u> cerase() const noexcept {
1538 * Create a new string by erasing all the characters after position `pos` from
1540 * \note Equivalent to `creplace(pos, min(count, pos - size()), "")`
1542 constexpr BasicFixedString cerase(std::size_t pos, std::size_t count = npos)
1543 const noexcept(false) {
1544 using A = const Char[1];
1547 detail::fixedstring::checkOverflowOrNpos(
1548 count, size_ - detail::fixedstring::checkOverflow(pos, size_)),
1552 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1553 * Compare two strings for lexicographical ordering.
1554 * \note Equivalent to
1555 * `compare(0, size(), that.data(), that.size())`
1557 template <std::size_t M>
1558 constexpr int compare(const BasicFixedString<Char, M>& that) const noexcept {
1559 return compare(0u, size_, that, 0u, that.size_);
1563 * Compare two strings for lexicographical ordering.
1564 * \note Equivalent to
1565 * `compare(this_pos, this_count, that.data(), that.size())`
1567 template <std::size_t M>
1568 constexpr int compare(
1569 std::size_t this_pos,
1570 std::size_t this_count,
1571 const BasicFixedString<Char, M>& that) const noexcept(false) {
1572 return compare(this_pos, this_count, that, 0u, that.size_);
1576 * Compare two strings for lexicographical ordering.
1577 * \note Equivalent to
1578 * `compare(this_pos, this_count, that.data() + that_pos, that_count)`
1580 template <std::size_t M>
1581 constexpr int compare(
1582 std::size_t this_pos,
1583 std::size_t this_count,
1584 const BasicFixedString<Char, M>& that,
1585 std::size_t that_pos,
1586 std::size_t that_count) const noexcept(false) {
1587 return static_cast<int>(detail::fixedstring::compare_(
1589 detail::fixedstring::checkOverflow(this_pos, size_),
1590 detail::fixedstring::checkOverflow(this_count, size_ - this_pos) +
1593 detail::fixedstring::checkOverflow(that_pos, that.size_),
1594 detail::fixedstring::checkOverflow(that_count, that.size_ - that_pos) +
1599 * Compare two strings for lexicographical ordering.
1600 * \note Equivalent to `compare(0, size(), that, strlen(that))`
1602 constexpr int compare(const Char* that) const noexcept {
1603 return compare(0u, size_, that, folly::constexpr_strlen(that));
1609 constexpr int compare(Range<const Char*> that) const noexcept {
1610 return compare(0u, size_, that.begin(), that.size());
1614 * Compare two strings for lexicographical ordering.
1615 * \note Equivalent to
1616 * `compare(this_pos, this_count, that, strlen(that))`
1618 constexpr int compare(
1619 std::size_t this_pos,
1620 std::size_t this_count,
1621 const Char* that) const noexcept(false) {
1622 return compare(this_pos, this_count, that, folly::constexpr_strlen(that));
1628 constexpr int compare(
1629 std::size_t this_pos,
1630 std::size_t this_count,
1631 Range<const Char*> that) const noexcept(false) {
1632 return compare(this_pos, this_count, that.begin(), that.size());
1636 * Compare two strings for lexicographical ordering.
1638 * Let `A` be the the
1639 * character sequence {`(*this)[this_pos]`, ...
1640 * `(*this)[this_pos + this_count - 1]`}. Let `B` be the character sequence
1641 * {`that[0]`, ...`that[count - 1]`}. Then...
1644 * - `< 0` if `A` is ordered before the `B`
1645 * - `> 0` if `B` is ordered before `A`
1646 * - `0` if `A` equals `B`.
1648 * \throw std::out_of_range if this_pos + this_count > size().
1650 constexpr int compare(
1651 std::size_t this_pos,
1652 std::size_t this_count,
1654 std::size_t that_count) const noexcept(false) {
1655 return static_cast<int>(detail::fixedstring::compare_(
1657 detail::fixedstring::checkOverflow(this_pos, size_),
1658 detail::fixedstring::checkOverflowOrNpos(this_count, size_ - this_pos) +
1665 constexpr int compare(
1666 std::size_t this_pos,
1667 std::size_t this_count,
1668 Range<const Char*> that,
1669 std::size_t that_count) const noexcept(false) {
1674 detail::fixedstring::checkOverflow(that_count, that.size()));
1677 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1678 * Return a substring from `pos` to the end of the string.
1679 * \note Equivalent to `BasicFixedString{*this, pos}`
1681 constexpr BasicFixedString substr(std::size_t pos) const noexcept(false) {
1682 return {*this, pos};
1686 * Return a substring from `pos` to the end of the string.
1687 * \note Equivalent to `BasicFixedString{*this, pos, count}`
1689 constexpr BasicFixedString substr(std::size_t pos, std::size_t count) const
1691 return {*this, pos, count};
1694 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1695 * Replace the characters in the range denoted by the half-open range
1696 * [`first`, `last`) with the string `that`.
1697 * \pre `first` and `last` point to characters within this string (including
1698 * the terminating null).
1699 * \note Equivalent to
1700 * `replace(first - data(), last - first, that.data(), that.size())`
1702 template <std::size_t M>
1703 FOLLY_CPP14_CONSTEXPR BasicFixedString& replace(
1706 const BasicFixedString<Char, M>& that) noexcept(false) {
1707 return replace(first - data_, last - first, that, 0u, that.size_);
1711 * Replace `this_count` characters starting from position `this_pos` with the
1712 * characters from string `that` starting at position `that_pos`.
1713 * \pre `that_pos <= that.size()`
1714 * \note Equivalent to
1715 * <tt>replace(this_pos, this_count, that.data() + that_pos,
1716 * that.size() - that_pos)</tt>
1718 template <std::size_t M>
1719 FOLLY_CPP14_CONSTEXPR BasicFixedString& replace(
1720 std::size_t this_pos,
1721 std::size_t this_count,
1722 const BasicFixedString<Char, M>& that,
1723 std::size_t that_pos = 0u) noexcept(false) {
1724 return replace(this_pos, this_count, that, that_pos, that.size_ - that_pos);
1728 * Replace `this_count` characters starting from position `this_pos` with
1729 * `that_count` characters from string `that` starting at position
1731 * \pre `that_pos <= that.size() && that_count <= that.size() - that_pos`
1732 * \note Equivalent to
1733 * `replace(this_pos, this_count, that.data() + that_pos, that_count)`
1735 template <std::size_t M>
1736 FOLLY_CPP14_CONSTEXPR BasicFixedString& replace(
1737 std::size_t this_pos,
1738 std::size_t this_count,
1739 const BasicFixedString<Char, M>& that,
1740 std::size_t that_pos,
1741 std::size_t that_count) noexcept(false) {
1742 return *this = creplace(this_pos, this_count, that, that_pos, that_count);
1746 * Replace `this_count` characters starting from position `this_pos` with
1747 * the characters from the string literal `that`.
1748 * \note Equivalent to
1749 * `replace(this_pos, this_count, that, strlen(that))`
1751 FOLLY_CPP14_CONSTEXPR BasicFixedString& replace(
1752 std::size_t this_pos,
1753 std::size_t this_count,
1754 const Char* that) noexcept(false) {
1755 return replace(this_pos, this_count, that, folly::constexpr_strlen(that));
1759 * Replace the characters denoted by the half-open range [`first`,`last`) with
1760 * the characters from the string literal `that`.
1761 * \pre `first` and `last` point to characters within this string (including
1762 * the terminating null).
1763 * \note Equivalent to
1764 * `replace(first - data(), last - first, that, strlen(that))`
1766 FOLLY_CPP14_CONSTEXPR BasicFixedString& replace(
1769 const Char* that) noexcept(false) {
1771 first - data_, last - first, that, folly::constexpr_strlen(that));
1775 * Replace `this_count` characters starting from position `this_pos` with
1776 * `that_count` characters from the character sequence pointed to by `that`.
1777 * \param this_pos The starting offset within `*this` of the first character
1779 * \param this_count The number of characters to be replaced. If `npos`,
1780 * it is treated as if `this_count` were `size() - this_pos`.
1781 * \param that A pointer to the replacement string.
1782 * \param that_count The number of characters in the replacement string.
1783 * \pre `this_pos <= size() && this_count <= size() - this_pos`
1784 * \pre `that` points to a contiguous sequence of at least `that_count`
1786 * \throw std::out_of_range on any of the following conditions:
1787 * - `this_pos > size()`
1788 * - `this_count > size() - this_pos`
1789 * - `size() - this_count + that_count > N`
1791 FOLLY_CPP14_CONSTEXPR BasicFixedString& replace(
1792 std::size_t this_pos,
1793 std::size_t this_count,
1795 std::size_t that_count) noexcept(false) {
1796 return *this = detail::fixedstring::Helper::replace_<Char>(
1799 detail::fixedstring::checkOverflow(this_pos, size_),
1800 detail::fixedstring::checkOverflowOrNpos(
1801 this_count, size_ - this_pos),
1809 * Replace `this_count` characters starting from position `this_pos` with
1810 * `that_count` characters `ch`.
1811 * \note Equivalent to
1812 * `replace(this_pos, this_count, BasicFixedString{that_count, ch})`
1814 FOLLY_CPP14_CONSTEXPR BasicFixedString& replace(
1815 std::size_t this_pos,
1816 std::size_t this_count,
1817 std::size_t that_count,
1818 Char ch) noexcept(false) {
1819 return replace(this_pos, this_count, BasicFixedString{that_count, ch});
1823 * Replace the characters denoted by the half-open range [`first`,`last`)
1824 * with `that_count` characters `ch`.
1825 * \note Equivalent to
1826 * `replace(first - data(), last - first, BasicFixedString{that_count, ch})`
1828 FOLLY_CPP14_CONSTEXPR BasicFixedString& replace(
1831 std::size_t that_count,
1832 Char ch) noexcept(false) {
1834 first - data_, last - first, BasicFixedString{that_count, ch});
1838 * Replace the characters denoted by the half-open range [`first`,`last`) with
1839 * the characters from the string literal `that`.
1840 * \pre `first` and `last` point to characters within this string (including
1841 * the terminating null).
1842 * \note Equivalent to
1843 * `replace(this_pos, this_count, il.begin(), il.size())`
1845 FOLLY_CPP14_CONSTEXPR BasicFixedString& replace(
1848 std::initializer_list<Char> il) noexcept(false) {
1849 return replace(first - data_, last - first, il.begin(), il.size());
1852 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
1853 * Construct a new string by replacing `this_count` characters starting from
1854 * position `this_pos` within this string with the characters from string
1855 * `that` starting at position `that_pos`.
1856 * \pre `that_pos <= that.size()`
1857 * \note Equivalent to
1858 * <tt>creplace(this_pos, this_count, that, that_pos,
1859 * that.size() - that_pos)</tt>
1861 template <std::size_t M>
1862 constexpr BasicFixedString<Char, N + M> creplace(
1863 std::size_t this_pos,
1864 std::size_t this_count,
1865 const BasicFixedString<Char, M>& that,
1866 std::size_t that_pos = 0u) const noexcept(false) {
1872 that.size_ - detail::fixedstring::checkOverflow(that_pos, that.size_));
1876 * Construct a new string by replacing `this_count` characters starting from
1877 * position `this_pos` within this string with `that_count` characters from
1878 * string `that` starting at position `that_pos`.
1879 * \param this_pos The starting offset within `*this` of the first character
1881 * \param this_count The number of characters to be replaced. If `npos`,
1882 * it is treated as if `this_count` were `size() - this_pos`.
1883 * \param that A string that contains the replacement string.
1884 * \param that_pos The offset to the first character in the replacement
1886 * \param that_count The number of characters in the replacement string.
1887 * \pre `this_pos <= size() && this_count <= size() - this_pos`
1888 * \pre `that_pos <= that.size() && that_count <= that.size() - that_pos`
1889 * \post The size of the returned string is `size() - this_count + that_count`
1890 * \note Equivalent to <tt>BasicFixedString<Char, N + M>{substr(0, this_pos) +
1891 * that.substr(that_pos, that_count) + substr(this_pos + this_count)}</tt>
1892 * \throw std::out_of_range on any of the following conditions:
1893 * - `this_pos > size()`
1894 * - `this_count > size() - this_pos`
1895 * - `that_pos > that.size()`
1896 * - `that_count > that.size() - that_pos`
1898 template <std::size_t M>
1899 constexpr BasicFixedString<Char, N + M> creplace(
1900 std::size_t this_pos,
1901 std::size_t this_count,
1902 const BasicFixedString<Char, M>& that,
1903 std::size_t that_pos,
1904 std::size_t that_count) const noexcept(false) {
1905 return detail::fixedstring::Helper::replace_<Char>(
1908 detail::fixedstring::checkOverflow(this_pos, size_),
1909 detail::fixedstring::checkOverflowOrNpos(this_count, size_ - this_pos),
1911 detail::fixedstring::checkOverflow(that_pos, that.size_),
1912 detail::fixedstring::checkOverflowOrNpos(
1913 that_count, that.size_ - that_pos),
1914 folly::make_index_sequence<N + M>{});
1918 * Construct a new string by replacing the characters denoted by the half-open
1919 * range [`first`,`last`) within this string with the characters from string
1920 * `that` starting at position `that_pos`.
1921 * \pre `that_pos <= that.size()`
1922 * \note Equivalent to
1923 * <tt>creplace(first - data(), last - first, that, that_pos,
1924 * that.size() - that_pos)</tt>
1926 template <std::size_t M>
1927 constexpr BasicFixedString<Char, N + M> creplace(
1930 const BasicFixedString<Char, M>& that,
1931 std::size_t that_pos = 0u) const noexcept(false) {
1937 that.size_ - detail::fixedstring::checkOverflow(that_pos, that.size_));
1941 * Construct a new string by replacing the characters denoted by the half-open
1942 * range [`first`,`last`) within this string with the `that_count`
1943 * characters from string `that` starting at position `that_pos`.
1944 * \note Equivalent to
1945 * <tt>creplace(first - data(), last - first, that, that_pos,
1948 template <std::size_t M>
1949 constexpr BasicFixedString<Char, N + M> creplace(
1952 const BasicFixedString<Char, M>& that,
1953 std::size_t that_pos,
1954 std::size_t that_count) const noexcept(false) {
1955 return creplace(first - data_, last - first, that, that_pos, that_count);
1959 * Construct a new string by replacing `this_count` characters starting from
1960 * position `this_pos` within this string with `M-1` characters from
1961 * character array `that`.
1962 * \pre `strlen(that) == M-1`
1963 * \note Equivalent to
1964 * <tt>creplace(this_pos, this_count, that, 0, M - 1)</tt>
1966 template <std::size_t M>
1967 constexpr BasicFixedString<Char, N + M - 1u> creplace(
1968 std::size_t this_pos,
1969 std::size_t this_count,
1970 const Char (&that)[M]) const noexcept(false) {
1971 return creplace(this_pos, this_count, that, 0u, M - 1u);
1975 * Replace `this_count` characters starting from position `this_pos` with
1976 * `that_count` characters from the character array `that` starting at
1977 * position `that_pos`.
1978 * \param this_pos The starting offset within `*this` of the first character
1980 * \param this_count The number of characters to be replaced. If `npos`,
1981 * it is treated as if `this_count` were `size() - this_pos`.
1982 * \param that An array of characters containing the replacement string.
1983 * \param that_pos The starting offset of the replacement string.
1984 * \param that_count The number of characters in the replacement string. If
1985 * `npos`, it is treated as if `that_count` were `M - 1 - that_pos`
1986 * \pre `this_pos <= size() && this_count <= size() - this_pos`
1987 * \pre `that_pos <= M - 1 && that_count <= M - 1 - that_pos`
1988 * \post The size of the returned string is `size() - this_count + that_count`
1989 * \note Equivalent to <tt>BasicFixedString<Char, N + M - 1>{
1990 * substr(0, this_pos) +
1991 * makeFixedString(that).substr(that_pos, that_count) +
1992 * substr(this_pos + this_count)}</tt>
1993 * \throw std::out_of_range on any of the following conditions:
1994 * - `this_pos > size()`
1995 * - `this_count > size() - this_pos`
1997 * - `that_count >= M - that_pos`
1999 template <std::size_t M>
2000 constexpr BasicFixedString<Char, N + M - 1u> creplace(
2001 std::size_t this_pos,
2002 std::size_t this_count,
2003 const Char (&that)[M],
2004 std::size_t that_pos,
2005 std::size_t that_count) const noexcept(false) {
2006 return detail::fixedstring::Helper::replace_<Char>(
2009 detail::fixedstring::checkOverflow(this_pos, size_),
2010 detail::fixedstring::checkOverflowOrNpos(this_count, size_ - this_pos),
2011 detail::fixedstring::checkNullTerminated(that),
2012 detail::fixedstring::checkOverflow(that_pos, M - 1u),
2013 detail::fixedstring::checkOverflowOrNpos(that_count, M - 1u - that_pos),
2014 folly::make_index_sequence<N + M - 1u>{});
2018 * Construct a new string by replacing the characters denoted by the half-open
2019 * range [`first`,`last`) within this string with the first `M-1`
2020 * characters from the character array `that`.
2021 * \pre `strlen(that) == M-1`
2022 * \note Equivalent to
2023 * <tt>creplace(first - data(), last - first, that, 0, M-1)</tt>
2025 template <std::size_t M>
2026 constexpr BasicFixedString<Char, N + M - 1u>
2027 creplace(const Char* first, const Char* last, const Char (&that)[M]) const
2029 return creplace(first - data_, last - first, that, 0u, M - 1u);
2033 * Construct a new string by replacing the characters denoted by the half-open
2034 * range [`first`,`last`) within this string with the `that_count`
2035 * characters from the character array `that` starting at position
2037 * \pre `strlen(that) == M-1`
2038 * \note Equivalent to
2039 * `creplace(first - data(), last - first, that, that_pos, that_count)`
2041 template <std::size_t M>
2042 constexpr BasicFixedString<Char, N + M - 1u> creplace(
2045 const Char (&that)[M],
2046 std::size_t that_pos,
2047 std::size_t that_count) const noexcept(false) {
2048 return creplace(first - data_, last - first, that, that_pos, that_count);
2051 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
2052 * Copies `min(count, size())` characters starting from offset `0`
2053 * from this string into the buffer pointed to by `dest`.
2054 * \return The number of characters copied.
2056 FOLLY_CPP14_CONSTEXPR std::size_t copy(Char* dest, std::size_t count) const
2058 return copy(dest, count, 0u);
2062 * Copies `min(count, size() - pos)` characters starting from offset `pos`
2063 * from this string into the buffer pointed to by `dest`.
2064 * \pre `pos <= size()`
2065 * \return The number of characters copied.
2066 * \throw std::out_of_range if `pos > size()`
2068 FOLLY_CPP14_CONSTEXPR std::size_t
2069 copy(Char* dest, std::size_t count, std::size_t pos) const noexcept(false) {
2070 detail::fixedstring::checkOverflow(pos, size_);
2071 for (std::size_t i = 0u; i < count; ++i) {
2072 if (i + pos == size_)
2074 dest[i] = data_[i + pos];
2079 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
2080 * Resizes the current string.
2081 * \note Equivalent to `resize(count, Char(0))`
2083 FOLLY_CPP14_CONSTEXPR void resize(std::size_t count) noexcept(false) {
2084 resize(count, Char(0));
2088 * Resizes the current string by setting the size to `count` and setting
2089 * `data()[count]` to `Char(0)`. If `count > old_size`, the characters
2090 * in the range [`old_size`,`count`) are set to `ch`.
2092 FOLLY_CPP14_CONSTEXPR void resize(std::size_t count, Char ch) noexcept(
2094 detail::fixedstring::checkOverflow(count, N);
2095 if (count == size_) {
2096 } else if (count < size_) {
2098 data_[size_] = Char(0);
2100 for (; size_ < count; ++size_) {
2103 data_[size_] = Char(0);
2107 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
2108 * Finds the first occurrence of the character sequence `that` in this string.
2109 * \note Equivalent to `find(that.data(), 0, that.size())`
2111 template <std::size_t M>
2112 constexpr std::size_t find(const BasicFixedString<Char, M>& that) const
2114 return find(that, 0u);
2118 * Finds the first occurrence of the character sequence `that` in this string,
2119 * starting at offset `pos`.
2120 * \pre `pos <= size()`
2121 * \note Equivalent to `find(that.data(), pos, that.size())`
2123 template <std::size_t M>
2124 constexpr std::size_t find(
2125 const BasicFixedString<Char, M>& that,
2126 std::size_t pos) const noexcept(false) {
2127 return that.size_ <= size_ - detail::fixedstring::checkOverflow(pos, size_)
2128 ? detail::fixedstring::find_(data_, size_, that.data_, pos, that.size_)
2133 * Finds the first occurrence of the character sequence `that` in this string.
2134 * \note Equivalent to `find(that.data(), 0, strlen(that))`
2136 constexpr std::size_t find(const Char* that) const noexcept {
2137 return find(that, 0u, folly::constexpr_strlen(that));
2141 * Finds the first occurrence of the character sequence `that` in this string,
2142 * starting at offset `pos`.
2143 * \pre `pos <= size()`
2144 * \note Equivalent to `find(that.data(), pos, strlen(that))`
2146 constexpr std::size_t find(const Char* that, std::size_t pos) const
2148 return find(that, pos, folly::constexpr_strlen(that));
2152 * Finds the first occurrence of the first `count` characters in the buffer
2153 * pointed to by `that` in this string, starting at offset `pos`.
2154 * \pre `pos <= size()`
2155 * \pre `that` points to a buffer containing at least `count` contiguous
2157 * \return The lowest offset `i` such that `i >= pos` and
2158 * `0 == strncmp(data() + i, that, count)`; or `npos` if there is no such
2160 * \throw std::out_of_range when `pos > size()`
2162 constexpr std::size_t find(
2165 std::size_t count) const noexcept(false) {
2166 return count <= size_ - detail::fixedstring::checkOverflow(pos, size_)
2167 ? detail::fixedstring::find_(data_, size_, that, pos, count)
2172 * Finds the first occurrence of the character `ch` in this string.
2173 * \note Equivalent to `find(&ch, 0, 1)`
2175 constexpr std::size_t find(Char ch) const noexcept {
2176 return find(ch, 0u);
2180 * Finds the first occurrence of the character character `c` in this string,
2181 * starting at offset `pos`.
2182 * \pre `pos <= size()`
2183 * \note Equivalent to `find(&ch, pos, 1)`
2185 constexpr std::size_t find(Char ch, std::size_t pos) const noexcept(false) {
2186 using A = const Char[1u];
2187 return 0u == size_ - detail::fixedstring::checkOverflow(pos, size_)
2189 : detail::fixedstring::find_(data_, size_, A{ch}, pos, 1u);
2192 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
2193 * Finds the last occurrence of characters in the string
2194 * `that` in this string.
2195 * \note Equivalent to `rfind(that.data(), size(), that.size())`
2197 template <std::size_t M>
2198 constexpr std::size_t rfind(const BasicFixedString<Char, M>& that) const
2200 return rfind(that, size_);
2204 * Finds the last occurrence of characters in the string
2205 * `that` in this string, starting at offset `pos`.
2206 * \note Equivalent to `rfind(that.data(), pos, that.size())`
2208 template <std::size_t M>
2209 constexpr std::size_t rfind(
2210 const BasicFixedString<Char, M>& that,
2211 std::size_t pos) const noexcept(false) {
2212 return that.size_ <= size_
2213 ? detail::fixedstring::rfind_(
2216 folly::constexpr_min(
2217 detail::fixedstring::checkOverflow(pos, size_),
2218 size_ - that.size_),
2224 * Finds the last occurrence of characters in the buffer
2225 * pointed to by `that` in this string.
2226 * \note Equivalent to `rfind(that, size(), strlen(that))`
2228 constexpr std::size_t rfind(const Char* that) const noexcept {
2229 return rfind(that, size_, folly::constexpr_strlen(that));
2233 * Finds the last occurrence of characters in the buffer
2234 * pointed to by `that` in this string, starting at offset `pos`.
2235 * \note Equivalent to `rfind(that, pos, strlen(that))`
2237 constexpr std::size_t rfind(const Char* that, std::size_t pos) const
2239 return rfind(that, pos, folly::constexpr_strlen(that));
2243 * Finds the last occurrence of the first `count` characters in the buffer
2244 * pointed to by `that` in this string, starting at offset `pos`.
2245 * \pre `pos <= size()`
2246 * \pre `that` points to a buffer containing at least `count` contiguous
2248 * \return The largest offset `i` such that `i <= pos` and
2249 * `i + count <= size()` and `0 == strncmp(data() + i, that, count)`; or
2250 * `npos` if there is no such offset `i`.
2251 * \throw std::out_of_range when `pos > size()`
2253 constexpr std::size_t rfind(
2256 std::size_t count) const noexcept(false) {
2257 return count <= size_
2258 ? detail::fixedstring::rfind_(
2261 folly::constexpr_min(
2262 detail::fixedstring::checkOverflow(pos, size_),
2269 * Finds the last occurrence of the character character `ch` in this string.
2270 * \note Equivalent to `rfind(&ch, size(), 1)`
2272 constexpr std::size_t rfind(Char ch) const noexcept {
2273 return rfind(ch, size_);
2277 * Finds the last occurrence of the character character `ch` in this string,
2278 * starting at offset `pos`.
2279 * \pre `pos <= size()`
2280 * \note Equivalent to `rfind(&ch, pos, 1)`
2282 constexpr std::size_t rfind(Char ch, std::size_t pos) const noexcept(false) {
2283 using A = const Char[1u];
2286 : detail::fixedstring::rfind_(
2289 folly::constexpr_min(
2290 detail::fixedstring::checkOverflow(pos, size_), size_ - 1u),
2294 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
2295 * Finds the first occurrence of any character in `that` in this string.
2296 * \note Equivalent to `find_first_of(that.data(), 0, that.size())`
2298 template <std::size_t M>
2299 constexpr std::size_t find_first_of(
2300 const BasicFixedString<Char, M>& that) const noexcept {
2301 return find_first_of(that, 0u);
2305 * Finds the first occurrence of any character in `that` in this string,
2306 * starting at offset `pos`
2307 * \note Equivalent to `find_first_of(that.data(), pos, that.size())`
2309 template <std::size_t M>
2310 constexpr std::size_t find_first_of(
2311 const BasicFixedString<Char, M>& that,
2312 std::size_t pos) const noexcept(false) {
2313 return size_ == detail::fixedstring::checkOverflow(pos, size_)
2315 : detail::fixedstring::find_first_of_(
2316 data_, size_, that.data_, pos, that.size_);
2320 * Finds the first occurrence of any character in the null-terminated
2321 * character sequence pointed to by `that` in this string.
2322 * \note Equivalent to `find_first_of(that, 0, strlen(that))`
2324 constexpr std::size_t find_first_of(const Char* that) const noexcept {
2325 return find_first_of(that, 0u, folly::constexpr_strlen(that));
2329 * Finds the first occurrence of any character in the null-terminated
2330 * character sequence pointed to by `that` in this string,
2331 * starting at offset `pos`
2332 * \note Equivalent to `find_first_of(that, pos, strlen(that))`
2334 constexpr std::size_t find_first_of(const Char* that, std::size_t pos) const
2336 return find_first_of(that, pos, folly::constexpr_strlen(that));
2340 * Finds the first occurrence of any character in the first `count` characters
2341 * in the buffer pointed to by `that` in this string, starting at offset
2343 * \pre `pos <= size()`
2344 * \pre `that` points to a buffer containing at least `count` contiguous
2346 * \return The smallest offset `i` such that `i >= pos` and
2347 * `std::find(that, that+count, at(i)) != that+count`; or
2348 * `npos` if there is no such offset `i`.
2349 * \throw std::out_of_range when `pos > size()`
2351 constexpr std::size_t find_first_of(
2354 std::size_t count) const noexcept(false) {
2355 return size_ == detail::fixedstring::checkOverflow(pos, size_)
2357 : detail::fixedstring::find_first_of_(data_, size_, that, pos, count);
2361 * Finds the first occurrence of `ch` in this string.
2362 * \note Equivalent to `find_first_of(&ch, 0, 1)`
2364 constexpr std::size_t find_first_of(Char ch) const noexcept {
2365 return find_first_of(ch, 0u);
2369 * Finds the first occurrence of `ch` in this string,
2370 * starting at offset `pos`.
2371 * \note Equivalent to `find_first_of(&ch, pos, 1)`
2373 constexpr std::size_t find_first_of(Char ch, std::size_t pos) const
2375 using A = const Char[1u];
2376 return size_ == detail::fixedstring::checkOverflow(pos, size_)
2378 : detail::fixedstring::find_first_of_(data_, size_, A{ch}, pos, 1u);
2381 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
2382 * Finds the first occurrence of any character not in `that` in this string.
2383 * \note Equivalent to `find_first_not_of(that.data(), 0, that.size())`
2385 template <std::size_t M>
2386 constexpr std::size_t find_first_not_of(
2387 const BasicFixedString<Char, M>& that) const noexcept {
2388 return find_first_not_of(that, 0u);
2391 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
2392 * Finds the first occurrence of any character not in `that` in this string.
2393 * \note Equivalent to `find_first_not_of(that.data(), 0, that.size())`
2395 template <std::size_t M>
2396 constexpr std::size_t find_first_not_of(
2397 const BasicFixedString<Char, M>& that,
2398 std::size_t pos) const noexcept(false) {
2399 return size_ == detail::fixedstring::checkOverflow(pos, size_)
2401 : detail::fixedstring::find_first_not_of_(
2402 data_, size_, that.data_, pos, that.size_);
2406 * Finds the first occurrence of any character not in the null-terminated
2407 * character sequence pointed to by `that` in this string.
2408 * \note Equivalent to `find_first_not_of(that, 0, strlen(that))`
2410 constexpr std::size_t find_first_not_of(const Char* that) const noexcept {
2411 return find_first_not_of(that, 0u, folly::constexpr_strlen(that));
2415 * Finds the first occurrence of any character not in the null-terminated
2416 * character sequence pointed to by `that` in this string,
2417 * starting at offset `pos`
2418 * \note Equivalent to `find_first_not_of(that, pos, strlen(that))`
2420 constexpr std::size_t find_first_not_of(const Char* that, std::size_t pos)
2421 const noexcept(false) {
2422 return find_first_not_of(that, pos, folly::constexpr_strlen(that));
2426 * Finds the first occurrence of any character not in the first `count`
2427 * characters in the buffer pointed to by `that` in this string, starting at
2429 * \pre `pos <= size()`
2430 * \pre `that` points to a buffer containing at least `count` contiguous
2432 * \return The smallest offset `i` such that `i >= pos` and
2433 * `std::find(that, that+count, at(i)) == that+count`; or
2434 * `npos` if there is no such offset `i`.
2435 * \throw std::out_of_range when `pos > size()`
2437 constexpr std::size_t find_first_not_of(
2440 std::size_t count) const noexcept(false) {
2441 return size_ == detail::fixedstring::checkOverflow(pos, size_)
2443 : detail::fixedstring::find_first_not_of_(
2444 data_, size_, that, pos, count);
2448 * Finds the first occurrence of any character other than `ch` in this string.
2449 * \note Equivalent to `find_first_not_of(&ch, 0, 1)`
2451 constexpr std::size_t find_first_not_of(Char ch) const noexcept {
2452 return find_first_not_of(ch, 0u);
2456 * Finds the first occurrence of any character other than `ch` in this string,
2457 * starting at offset `pos`.
2458 * \note Equivalent to `find_first_not_of(&ch, pos, 1)`
2460 constexpr std::size_t find_first_not_of(Char ch, std::size_t pos) const
2462 using A = const Char[1u];
2463 return 1u <= size_ - detail::fixedstring::checkOverflow(pos, size_)
2464 ? detail::fixedstring::find_first_not_of_(data_, size_, A{ch}, pos, 1u)
2468 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
2469 * Finds the last occurrence of any character in `that` in this string.
2470 * \note Equivalent to `find_last_of(that.data(), size(), that.size())`
2472 template <std::size_t M>
2473 constexpr std::size_t find_last_of(
2474 const BasicFixedString<Char, M>& that) const noexcept {
2475 return find_last_of(that, size_);
2479 * Finds the last occurrence of any character in `that` in this string,
2480 * starting at offset `pos`
2481 * \note Equivalent to `find_last_of(that.data(), pos, that.size())`
2483 template <std::size_t M>
2484 constexpr std::size_t find_last_of(
2485 const BasicFixedString<Char, M>& that,
2486 std::size_t pos) const noexcept(false) {
2489 : detail::fixedstring::find_last_of_(
2492 folly::constexpr_min(
2493 detail::fixedstring::checkOverflow(pos, size_), size_ - 1u),
2498 * Finds the last occurrence of any character in the null-terminated
2499 * character sequence pointed to by `that` in this string.
2500 * \note Equivalent to `find_last_of(that, size(), strlen(that))`
2502 constexpr std::size_t find_last_of(const Char* that) const noexcept {
2503 return find_last_of(that, size_, folly::constexpr_strlen(that));
2507 * Finds the last occurrence of any character in the null-terminated
2508 * character sequence pointed to by `that` in this string,
2509 * starting at offset `pos`
2510 * \note Equivalent to `find_last_of(that, pos, strlen(that))`
2512 constexpr std::size_t find_last_of(const Char* that, std::size_t pos) const
2514 return find_last_of(that, pos, folly::constexpr_strlen(that));
2518 * Finds the last occurrence of any character in the first `count` characters
2519 * in the buffer pointed to by `that` in this string, starting at offset
2521 * \pre `pos <= size()`
2522 * \pre `that` points to a buffer containing at least `count` contiguous
2524 * \return The largest offset `i` such that `i <= pos` and
2525 * `i < size()` and `std::find(that, that+count, at(i)) != that+count`; or
2526 * `npos` if there is no such offset `i`.
2527 * \throw std::out_of_range when `pos > size()`
2529 constexpr std::size_t find_last_of(
2532 std::size_t count) const noexcept(false) {
2535 : detail::fixedstring::find_last_of_(
2538 folly::constexpr_min(
2539 detail::fixedstring::checkOverflow(pos, size_), size_ - 1u),
2544 * Finds the last occurrence of `ch` in this string.
2545 * \note Equivalent to `find_last_of(&ch, size(), 1)`
2547 constexpr std::size_t find_last_of(Char ch) const noexcept {
2548 return find_last_of(ch, size_);
2552 * Finds the last occurrence of `ch` in this string,
2553 * starting at offset `pos`.
2554 * \note Equivalent to `find_last_of(&ch, pos, 1)`
2556 constexpr std::size_t find_last_of(Char ch, std::size_t pos) const
2558 using A = const Char[1u];
2561 : detail::fixedstring::find_last_of_(
2564 folly::constexpr_min(
2565 detail::fixedstring::checkOverflow(pos, size_), size_ - 1u),
2569 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
2570 * Finds the last occurrence of any character not in `that` in this string.
2571 * \note Equivalent to `find_last_not_of(that.data(), size(), that.size())`
2573 template <std::size_t M>
2574 constexpr std::size_t find_last_not_of(
2575 const BasicFixedString<Char, M>& that) const noexcept {
2576 return find_last_not_of(that, size_);
2580 * Finds the last occurrence of any character not in `that` in this string,
2581 * starting at offset `pos`
2582 * \note Equivalent to `find_last_not_of(that.data(), pos, that.size())`
2584 template <std::size_t M>
2585 constexpr std::size_t find_last_not_of(
2586 const BasicFixedString<Char, M>& that,
2587 std::size_t pos) const noexcept(false) {
2590 : detail::fixedstring::find_last_not_of_(
2593 folly::constexpr_min(
2594 detail::fixedstring::checkOverflow(pos, size_), size_ - 1u),
2599 * Finds the last occurrence of any character not in the null-terminated
2600 * character sequence pointed to by `that` in this string.
2601 * \note Equivalent to `find_last_not_of(that, size(), strlen(that))`
2603 constexpr std::size_t find_last_not_of(const Char* that) const noexcept {
2604 return find_last_not_of(that, size_, folly::constexpr_strlen(that));
2608 * Finds the last occurrence of any character not in the null-terminated
2609 * character sequence pointed to by `that` in this string,
2610 * starting at offset `pos`
2611 * \note Equivalent to `find_last_not_of(that, pos, strlen(that))`
2613 constexpr std::size_t find_last_not_of(const Char* that, std::size_t pos)
2614 const noexcept(false) {
2615 return find_last_not_of(that, pos, folly::constexpr_strlen(that));
2619 * Finds the last occurrence of any character not in the first `count`
2620 * characters in the buffer pointed to by `that` in this string, starting at
2622 * \pre `pos <= size()`
2623 * \pre `that` points to a buffer containing at least `count` contiguous
2625 * \return The largest offset `i` such that `i <= pos` and
2626 * `i < size()` and `std::find(that, that+count, at(i)) == that+count`; or
2627 * `npos` if there is no such offset `i`.
2628 * \throw std::out_of_range when `pos > size()`
2630 constexpr std::size_t find_last_not_of(
2633 std::size_t count) const noexcept(false) {
2636 : detail::fixedstring::find_last_not_of_(
2639 folly::constexpr_min(
2640 detail::fixedstring::checkOverflow(pos, size_), size_ - 1u),
2645 * Finds the last occurrence of any character other than `ch` in this string.
2646 * \note Equivalent to `find_last_not_of(&ch, size(), 1)`
2648 constexpr std::size_t find_last_not_of(Char ch) const noexcept {
2649 return find_last_not_of(ch, size_);
2653 * Finds the last occurrence of any character other than `ch` in this string,
2654 * starting at offset `pos`.
2655 * \note Equivalent to `find_last_not_of(&ch, pos, 1)`
2657 constexpr std::size_t find_last_not_of(Char ch, std::size_t pos) const
2659 using A = const Char[1u];
2662 : detail::fixedstring::find_last_not_of_(
2665 folly::constexpr_min(
2666 detail::fixedstring::checkOverflow(pos, size_), size_ - 1u),
2670 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
2671 * Asymmetric relational operators
2673 friend constexpr bool operator==(
2675 const BasicFixedString& b) noexcept {
2676 return detail::fixedstring::equal_(
2677 a, folly::constexpr_strlen(a), b.data_, b.size_);
2683 friend constexpr bool operator==(
2684 const BasicFixedString& a,
2685 const Char* b) noexcept {
2692 friend constexpr bool operator==(
2693 Range<const Char*> a,
2694 const BasicFixedString& b) noexcept {
2695 return detail::fixedstring::equal_(a.begin(), a.size(), b.data_, b.size_);
2701 friend constexpr bool operator==(
2702 const BasicFixedString& a,
2703 Range<const Char*> b) noexcept {
2707 friend constexpr bool operator!=(
2709 const BasicFixedString& b) noexcept {
2716 friend constexpr bool operator!=(
2717 const BasicFixedString& a,
2718 const Char* b) noexcept {
2725 friend constexpr bool operator!=(
2726 Range<const Char*> a,
2727 const BasicFixedString& b) noexcept {
2734 friend constexpr bool operator!=(
2735 const BasicFixedString& a,
2736 Range<const Char*> b) noexcept {
2740 friend constexpr bool operator<(
2742 const BasicFixedString& b) noexcept {
2743 return detail::fixedstring::Cmp::LT ==
2744 detail::fixedstring::compare_(
2745 a, 0u, folly::constexpr_strlen(a), b.data_, 0u, b.size_);
2751 friend constexpr bool operator<(
2752 const BasicFixedString& a,
2753 const Char* b) noexcept {
2754 return detail::fixedstring::Cmp::LT ==
2755 detail::fixedstring::compare_(
2756 a.data_, 0u, a.size_, b, 0u, folly::constexpr_strlen(b));
2762 friend constexpr bool operator<(
2763 Range<const Char*> a,
2764 const BasicFixedString& b) noexcept {
2765 return detail::fixedstring::Cmp::LT ==
2766 detail::fixedstring::compare_(
2767 a.begin(), 0u, a.size(), b.data_, 0u, b.size_);
2773 friend constexpr bool operator<(
2774 const BasicFixedString& a,
2775 Range<const Char*> b) noexcept {
2776 return detail::fixedstring::Cmp::LT ==
2777 detail::fixedstring::compare_(
2778 a.data_, 0u, a.size_, b.begin(), 0u, b.size());
2781 friend constexpr bool operator>(
2783 const BasicFixedString& b) noexcept {
2790 friend constexpr bool operator>(
2791 const BasicFixedString& a,
2792 const Char* b) noexcept {
2799 friend constexpr bool operator>(
2800 Range<const Char*> a,
2801 const BasicFixedString& b) noexcept {
2808 friend constexpr bool operator>(
2809 const BasicFixedString& a,
2810 Range<const Char*> b) noexcept {
2814 friend constexpr bool operator<=(
2816 const BasicFixedString& b) noexcept {
2823 friend constexpr bool operator<=(
2824 const BasicFixedString& a,
2825 const Char* b) noexcept {
2832 friend constexpr bool operator<=(
2833 Range<const Char*> const& a,
2834 const BasicFixedString& b) noexcept {
2841 friend constexpr bool operator<=(
2842 const BasicFixedString& a,
2843 Range<const Char*> b) noexcept {
2847 friend constexpr bool operator>=(
2849 const BasicFixedString& b) noexcept {
2856 friend constexpr bool operator>=(
2857 const BasicFixedString& a,
2858 const Char* b) noexcept {
2865 friend constexpr bool operator>=(
2866 Range<const Char*> a,
2867 const BasicFixedString& b) noexcept {
2874 friend constexpr bool operator>=(
2875 const BasicFixedString& a,
2876 Range<const Char*> const& b) noexcept {
2880 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
2881 * Asymmetric concatenation
2883 template <std::size_t M>
2884 friend constexpr BasicFixedString<Char, N + M - 1u> operator+(
2886 const BasicFixedString& b) noexcept {
2887 return detail::fixedstring::Helper::concat_<Char>(
2888 detail::fixedstring::checkNullTerminated(a),
2892 folly::make_index_sequence<N + M - 1u>{});
2898 template <std::size_t M>
2899 friend constexpr BasicFixedString<Char, N + M - 1u> operator+(
2900 const BasicFixedString& a,
2901 const Char (&b)[M]) noexcept {
2902 return detail::fixedstring::Helper::concat_<Char>(
2905 detail::fixedstring::checkNullTerminated(b),
2907 folly::make_index_sequence<N + M - 1u>{});
2913 friend constexpr BasicFixedString<Char, N + 1u> operator+(
2915 const BasicFixedString& b) noexcept {
2916 using A = const Char[2u];
2917 return detail::fixedstring::Helper::concat_<Char>(
2922 folly::make_index_sequence<N + 1u>{});
2928 friend constexpr BasicFixedString<Char, N + 1u> operator+(
2929 const BasicFixedString& a,
2931 using A = const Char[2u];
2932 return detail::fixedstring::Helper::concat_<Char>(
2937 folly::make_index_sequence<N + 1u>{});
2941 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
2942 * Symmetric relational operators
2944 template <class Char, std::size_t A, std::size_t B>
2945 constexpr bool operator==(
2946 const BasicFixedString<Char, A>& a,
2947 const BasicFixedString<Char, B>& b) noexcept {
2948 return detail::fixedstring::equal_(
2949 detail::fixedstring::Helper::data_(a),
2951 detail::fixedstring::Helper::data_(b),
2955 template <class Char, std::size_t A, std::size_t B>
2956 constexpr bool operator!=(
2957 const BasicFixedString<Char, A>& a,
2958 const BasicFixedString<Char, B>& b) {
2962 template <class Char, std::size_t A, std::size_t B>
2963 constexpr bool operator<(
2964 const BasicFixedString<Char, A>& a,
2965 const BasicFixedString<Char, B>& b) noexcept {
2966 return detail::fixedstring::Cmp::LT ==
2967 detail::fixedstring::compare_(
2968 detail::fixedstring::Helper::data_(a),
2971 detail::fixedstring::Helper::data_(b),
2976 template <class Char, std::size_t A, std::size_t B>
2977 constexpr bool operator>(
2978 const BasicFixedString<Char, A>& a,
2979 const BasicFixedString<Char, B>& b) noexcept {
2983 template <class Char, std::size_t A, std::size_t B>
2984 constexpr bool operator<=(
2985 const BasicFixedString<Char, A>& a,
2986 const BasicFixedString<Char, B>& b) noexcept {
2990 template <class Char, std::size_t A, std::size_t B>
2991 constexpr bool operator>=(
2992 const BasicFixedString<Char, A>& a,
2993 const BasicFixedString<Char, B>& b) noexcept {
2997 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
2998 * Symmetric concatenation
3000 template <class Char, std::size_t N, std::size_t M>
3001 constexpr BasicFixedString<Char, N + M> operator+(
3002 const BasicFixedString<Char, N>& a,
3003 const BasicFixedString<Char, M>& b) noexcept {
3004 return detail::fixedstring::Helper::concat_<Char>(
3005 detail::fixedstring::Helper::data_(a),
3007 detail::fixedstring::Helper::data_(b),
3009 folly::make_index_sequence<N + M>{});
3012 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
3013 * Construct a `BasicFixedString` object from a null-terminated array of
3014 * characters. The capacity and size of the string will be equal to one less
3015 * than the size of the array.
3016 * \pre `a` contains no embedded null characters.
3017 * \pre `a[N-1] == Char(0)`
3018 * \post For a returned string `s`, `s[i]==a[i]` for every `i` in [`0`,`N-1`].
3020 template <class Char, std::size_t N>
3021 constexpr BasicFixedString<Char, N - 1u> makeFixedString(
3022 const Char (&a)[N]) noexcept {
3026 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
3029 template <class Char, std::size_t N>
3030 FOLLY_CPP14_CONSTEXPR void swap(
3031 BasicFixedString<Char, N>& a,
3032 BasicFixedString<Char, N>& b) noexcept {
3036 inline namespace literals {
3037 inline namespace string_literals {
3039 // "const std::size_t&" is so that folly::npos has the same address in every
3040 // translation unit. This is to avoid potential violations of the ODR.
3041 constexpr const std::size_t& npos = detail::fixedstring::FixedStringBase::npos;
3044 #if defined(__GNUC__)
3045 #pragma GCC diagnostic push
3046 #pragma GCC diagnostic ignored "-Wpragmas"
3047 #pragma GCC diagnostic ignored "-Wgnu-string-literal-operator-template"
3049 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** *
3050 * User-defined literals for creating FixedString objects from string literals
3051 * on the compilers that support it.
3056 * using namespace folly::string_literals;
3057 * constexpr auto hello = "hello world!"_fs;
3060 * \note This requires a GNU compiler extension
3061 * (-Wgnu-string-literal-operator-template) supported by clang and gcc,
3062 * proposed for standardization in
3063 * <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0424r0.pdf>.
3065 * For portable code, prefer the suffixes `_fs4`, `_fs8`, `_fs16`, `_fs32`,
3066 * `_fs64`, and `_fs128` for creating instances of types `FixedString<4>`,
3067 * `FixedString<8>`, `FixedString<16>`, etc.
3069 template <class Char, Char... Cs>
3070 constexpr BasicFixedString<Char, sizeof...(Cs)> operator"" _fs() noexcept {
3071 using A = const Char[sizeof...(Cs) + 1u];
3072 // The `+` in `+A{etc}` forces the array type to decay to a pointer
3073 return {+A{Cs..., Char(0)}, sizeof...(Cs)};
3076 #pragma GCC diagnostic pop
3079 #define FOLLY_DEFINE_FIXED_STRING_UDL(N) \
3080 constexpr FixedString<N> operator"" _fs##N( \
3081 const char* that, std::size_t count) noexcept(false) { \
3082 return {that, count}; \
3086 // Define UDLs _fs4, _fs8, _fs16, etc for FixedString<[4, 8, 16, ...]>
3087 FOLLY_DEFINE_FIXED_STRING_UDL(4)
3088 FOLLY_DEFINE_FIXED_STRING_UDL(8)
3089 FOLLY_DEFINE_FIXED_STRING_UDL(16)
3090 FOLLY_DEFINE_FIXED_STRING_UDL(32)
3091 FOLLY_DEFINE_FIXED_STRING_UDL(64)
3092 FOLLY_DEFINE_FIXED_STRING_UDL(128)
3094 #undef FOLLY_DEFINE_FIXED_STRING_UDL
3099 // // numeric conversions:
3100 // template <std::size_t N>
3101 // constexpr int stoi(const FixedString<N>& str, int base = 10);
3102 // template <std::size_t N>
3103 // constexpr unsigned stou(const FixedString<N>& str, int base = 10);
3104 // template <std::size_t N>
3105 // constexpr long stol(const FixedString<N>& str, int base = 10);
3106 // template <std::size_t N>
3107 // constexpr unsigned long stoul(const FixedString<N>& str, int base = 10;
3108 // template <std::size_t N>
3109 // constexpr long long stoll(const FixedString<N>& str, int base = 10);
3110 // template <std::size_t N>
3111 // constexpr unsigned long long stoull(const FixedString<N>& str,
3113 // template <std::size_t N>
3114 // constexpr float stof(const FixedString<N>& str);
3115 // template <std::size_t N>
3116 // constexpr double stod(const FixedString<N>& str);
3117 // template <std::size_t N>
3118 // constexpr long double stold(const FixedString<N>& str);
3119 // template <int val>
3120 // constexpr FixedString</*...*/> to_fixed_string_i() noexcept;
3121 // template <unsigned val>
3122 // constexpr FixedString</*...*/> to_fixed_string_u() noexcept;
3123 // template <long val>
3124 // constexpr FixedString</*...*/> to_fixed_string_l() noexcept;
3125 // template <unsigned long val>
3126 // constexpr FixedString</*...*/> to_fixed_string_ul() noexcept;
3127 // template <long long val>
3128 // constexpr FixedString</*...*/> to_fixed_string_ll() noexcept
3129 // template <unsigned long long val>
3130 // constexpr FixedString</*...*/> to_fixed_string_ull() noexcept;