fixed_string: add constexpr equality operators

This fixes some errors seen under UBSan when comparing fixed_string
objects in std::integral_constant under GCC.

In particular the M != N case appears to be important.
This commit is contained in:
Danny Robson 2024-09-24 14:01:57 +10:00
parent 7dec7b63f3
commit a44260b8b4

View File

@ -43,9 +43,18 @@ namespace cruft {
auto begin (void) const& noexcept { return std::begin (value); } auto begin (void) const& noexcept { return std::begin (value); }
auto end (void) const& noexcept { return std::end (value); } auto end (void) const& noexcept { return std::end (value); }
};
constexpr bool
operator== (fixed_string<N> const&) const noexcept = default;
template <std::size_t M>
requires (M != N)
constexpr bool
operator== (fixed_string<M> const&) const noexcept
{ return false; }
};
template <std::size_t N> template <std::size_t N>
fixed_string (char const (&)[N]) -> fixed_string<N - 1>; fixed_string (char const (&)[N]) -> fixed_string<N - 1>;
} }