#include <type_traits>
#include <utility>
+#include <folly/Range.h>
+#include <folly/Utility.h>
#include <folly/portability/BitsFunctexcept.h>
#include <folly/portability/Constexpr.h>
// Rather annoyingly, GCC's -Warray-bounds warning issues false positives for
// this code. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61971
-#if defined(__GNUC__) && !defined(__CLANG__) && __GNUC__ <= 4
+#if defined(__GNUC__) && !defined(__CLANG__) && __GNUC__ <= 5
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
#endif
std::size_t left_count,
const Right& right,
std::size_t right_count,
- std::index_sequence<Is...> is) noexcept {
+ folly::index_sequence<Is...> is) noexcept {
return {left, left_count, right, right_count, is};
}
const Right& right,
std::size_t right_pos,
std::size_t right_count,
- std::index_sequence<Is...> is) noexcept {
+ folly::index_sequence<Is...> is) noexcept {
return {left,
left_size,
left_pos,
} // namespace fixedstring
} // namespace detail
-// Defined in folly/Range.h
-template <class Iter>
-class Range;
-
// Defined in folly/Hash.h
std::uint32_t hsieh_hash32_buf(const void* buf, std::size_t len);
Char data_[N + 1u]; // +1 for the null terminator
std::size_t size_; // Nbr of chars, not incl. null terminator. size_ <= N.
- using Indices = std::make_index_sequence<N>;
+ using Indices = folly::make_index_sequence<N>;
template <class That, std::size_t... Is>
constexpr BasicFixedString(
const That& that,
std::size_t size,
- std::index_sequence<Is...>,
+ folly::index_sequence<Is...>,
std::size_t pos = 0,
std::size_t count = npos) noexcept
: data_{(Is < (size - pos) && Is < count ? that[Is + pos] : Char(0))...,
constexpr BasicFixedString(
std::size_t count,
Char ch,
- std::index_sequence<Is...>) noexcept
+ folly::index_sequence<Is...>) noexcept
: data_{((Is < count) ? ch : Char(0))..., Char(0)}, size_{count} {}
// Concatenation constructor
std::size_t left_size,
const Right& right,
std::size_t right_size,
- std::index_sequence<Is...>) noexcept
+ folly::index_sequence<Is...>) noexcept
: data_{detail::fixedstring::char_at_<Char>(
left,
left_size,
const Right& right,
std::size_t right_pos,
std::size_t right_count,
- std::index_sequence<Is...>) noexcept
+ folly::index_sequence<Is...>) noexcept
: data_{detail::fixedstring::char_at_<Char>(
left,
left_size,
: BasicFixedString{
that.data_,
that.size_,
- std::make_index_sequence<(M < N ? M : N)>{},
+ folly::make_index_sequence<(M < N ? M : N)>{},
pos,
detail::fixedstring::checkOverflow(
detail::fixedstring::checkOverflowOrNpos(
constexpr /* implicit */ BasicFixedString(const Char (&that)[M]) noexcept
: BasicFixedString{detail::fixedstring::checkNullTerminated(that),
M - 1u,
- std::make_index_sequence<M - 1u>{}} {}
+ folly::make_index_sequence<M - 1u>{}} {}
/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
* Construct from a `const Char*` and count
return compare(0u, size_, that, folly::constexpr_strlen(that));
}
+ /**
+ * \overload
+ */
+ constexpr int compare(Range<const Char*> that) const noexcept {
+ return compare(0u, size_, that.begin(), that.size());
+ }
+
/**
* Compare two strings for lexicographical ordering.
* \note Equivalent to
return compare(this_pos, this_count, that, folly::constexpr_strlen(that));
}
+ /**
+ * \overload
+ */
+ constexpr int compare(
+ std::size_t this_pos,
+ std::size_t this_count,
+ Range<const Char*> that) const noexcept(false) {
+ return compare(this_pos, this_count, that.begin(), that.size());
+ }
+
/**
* Compare two strings for lexicographical ordering.
*
that_count));
}
+ constexpr int compare(
+ std::size_t this_pos,
+ std::size_t this_count,
+ Range<const Char*> that,
+ std::size_t that_count) const noexcept(false) {
+ return compare(
+ this_pos,
+ this_count,
+ that.begin(),
+ detail::fixedstring::checkOverflow(that_count, that.size()));
+ }
+
/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
* Return a substring from `pos` to the end of the string.
* \note Equivalent to `BasicFixedString{*this, pos}`
detail::fixedstring::checkOverflow(that_pos, that.size_),
detail::fixedstring::checkOverflowOrNpos(
that_count, that.size_ - that_pos),
- std::make_index_sequence<N + M>{});
+ folly::make_index_sequence<N + M>{});
}
/**
detail::fixedstring::checkNullTerminated(that),
detail::fixedstring::checkOverflow(that_pos, M - 1u),
detail::fixedstring::checkOverflowOrNpos(that_count, M - 1u - that_pos),
- std::make_index_sequence<N + M - 1u>{});
+ folly::make_index_sequence<N + M - 1u>{});
}
/**
return b == a;
}
+ /**
+ * \overload
+ */
+ friend constexpr bool operator==(
+ Range<const Char*> a,
+ const BasicFixedString& b) noexcept {
+ return detail::fixedstring::equal_(a.begin(), a.size(), b.data_, b.size_);
+ }
+
+ /**
+ * \overload
+ */
+ friend constexpr bool operator==(
+ const BasicFixedString& a,
+ Range<const Char*> b) noexcept {
+ return b == a;
+ }
+
friend constexpr bool operator!=(
const Char* a,
const BasicFixedString& b) noexcept {
return !(b == a);
}
+ /**
+ * \overload
+ */
+ friend constexpr bool operator!=(
+ Range<const Char*> a,
+ const BasicFixedString& b) noexcept {
+ return !(a == b);
+ }
+
+ /**
+ * \overload
+ */
+ friend constexpr bool operator!=(
+ const BasicFixedString& a,
+ Range<const Char*> b) noexcept {
+ return !(a == b);
+ }
+
friend constexpr bool operator<(
const Char* a,
const BasicFixedString& b) noexcept {
a.data_, 0u, a.size_, b, 0u, folly::constexpr_strlen(b));
}
+ /**
+ * \overload
+ */
+ friend constexpr bool operator<(
+ Range<const Char*> a,
+ const BasicFixedString& b) noexcept {
+ return detail::fixedstring::Cmp::LT ==
+ detail::fixedstring::compare_(
+ a.begin(), 0u, a.size(), b.data_, 0u, b.size_);
+ }
+
+ /**
+ * \overload
+ */
+ friend constexpr bool operator<(
+ const BasicFixedString& a,
+ Range<const Char*> b) noexcept {
+ return detail::fixedstring::Cmp::LT ==
+ detail::fixedstring::compare_(
+ a.data_, 0u, a.size_, b.begin(), 0u, b.size());
+ }
+
friend constexpr bool operator>(
const Char* a,
const BasicFixedString& b) noexcept {
return b < a;
}
+ /**
+ * \overload
+ */
+ friend constexpr bool operator>(
+ Range<const Char*> a,
+ const BasicFixedString& b) noexcept {
+ return b < a;
+ }
+
+ /**
+ * \overload
+ */
+ friend constexpr bool operator>(
+ const BasicFixedString& a,
+ Range<const Char*> b) noexcept {
+ return b < a;
+ }
+
friend constexpr bool operator<=(
const Char* a,
const BasicFixedString& b) noexcept {
return !(b < a);
}
+ /**
+ * \overload
+ */
+ friend constexpr bool operator<=(
+ Range<const Char*> const& a,
+ const BasicFixedString& b) noexcept {
+ return !(b < a);
+ }
+
+ /**
+ * \overload
+ */
+ friend constexpr bool operator<=(
+ const BasicFixedString& a,
+ Range<const Char*> b) noexcept {
+ return !(b < a);
+ }
+
friend constexpr bool operator>=(
const Char* a,
const BasicFixedString& b) noexcept {
return !(a < b);
}
+ /**
+ * \overload
+ */
+ friend constexpr bool operator>=(
+ Range<const Char*> a,
+ const BasicFixedString& b) noexcept {
+ return !(a < b);
+ }
+
+ /**
+ * \overload
+ */
+ friend constexpr bool operator>=(
+ const BasicFixedString& a,
+ Range<const Char*> const& b) noexcept {
+ return !(a < b);
+ }
+
/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
* Asymmetric concatenation
*/
M - 1u,
b.data_,
b.size_,
- std::make_index_sequence<N + M - 1u>{});
+ folly::make_index_sequence<N + M - 1u>{});
}
/**
a.size_,
detail::fixedstring::checkNullTerminated(b),
M - 1u,
- std::make_index_sequence<N + M - 1u>{});
+ folly::make_index_sequence<N + M - 1u>{});
}
/**
1u,
b.data_,
b.size_,
- std::make_index_sequence<N + 1u>{});
+ folly::make_index_sequence<N + 1u>{});
}
/**
a.size_,
A{b, Char(0)},
1u,
- std::make_index_sequence<N + 1u>{});
+ folly::make_index_sequence<N + 1u>{});
}
};
a.size(),
detail::fixedstring::Helper::data_(b),
b.size(),
- std::make_index_sequence<N + M>{});
+ folly::make_index_sequence<N + M>{});
}
/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **