5 Quantities and units library [quantities]

5.3 Utilities [qty.utils]

5.3.3 Symbol text [qty.sym.txt]

namespace mp_units { template<std::size_t N, std::size_t M> class symbol_text { public: std::fixed_u8string<N> utf8; // exposition only std::fixed_string<M> portable; // exposition only // constructors constexpr symbol_text(char portable); consteval symbol_text(const char (&portable)[N + 1]); constexpr symbol_text(const std::fixed_string<N>& portable); consteval symbol_text(const char8_t (&utf8)[N + 1], const char (&portable)[M + 1]); constexpr symbol_text(const std::fixed_u8string<N>& utf8, const std::fixed_string<M>& portable); // observers constexpr const auto& utf8() const { return utf8; } constexpr const auto& portable() const { return portable; } constexpr bool empty() const { return utf8().empty(); } // string operations template<std::size_t N2, std::size_t M2> friend constexpr symbol_text<N + N2, M + M2> operator+(const symbol_text& lhs, const symbol_text<N2, M2>& rhs); // comparison template<std::size_t N2, std::size_t M2> friend constexpr bool operator==(const symbol_text& lhs, const symbol_text<N2, M2>& rhs) noexcept; template<std::size_t N2, std::size_t M2> friend constexpr auto operator<=>(const symbol_text& lhs, const symbol_text<N2, M2>& rhs) noexcept; }; symbol_text(char) -> symbol_text<1, 1>; template<std::size_t N> symbol_text(const char (&)[N]) -> symbol_text<N - 1, N - 1>; template<std::size_t N> symbol_text(const std::fixed_string<N>&) -> symbol_text<N, N>; template<std::size_t N, std::size_t M> symbol_text(const char8_t (&)[N], const char (&)[M]) -> symbol_text<N - 1, M - 1>; template<std::size_t N, std::size_t M> symbol_text(const std::fixed_u8string<N>&, const std::fixed_string<M>&) -> symbol_text<N, M>; }
symbol_text represents a symbol text.
utf8 stores its UTF-8 representation, and portable stores its portable representation.
symbol_text<N, M> is a structural type (N4971, [temp.param]).
In the descriptions that follow, it is a Precondition that
  • values of char are in the basic literal character set (N4971, [lex.charset]), and
  • for a parameter of the form const CharT (&txt)[M], (txt[M - 1] == CharT()) is true.
constexpr symbol_text(char portable); consteval symbol_text(const char (&portable)[N + 1]); constexpr symbol_text(const std::fixed_string<N>& portable); consteval symbol_text(const char8_t (&utf8)[N + 1], const char (&portable)[M + 1]); constexpr symbol_text(const std::fixed_u8string<N>& utf8, const std::fixed_string<M>& portable);
For the constructors without a parameter named utf8, let utf8 be: std::bit_cast<std::fixed_u8string<N>>(std::basic_fixed_string(portable))
Effects: Equivalent to the mem-initializer-list: utf8{utf8}, portable{portable}
template<std::size_t N2, std::size_t M2> friend constexpr symbol_text<N + N2, M + M2> operator+(const symbol_text& lhs, const symbol_text<N2, M2>& rhs);
Effects: Equivalent to: return symbol_text<N + N2, M + M2>(lhs.utf8() + rhs.utf8(), lhs.portable() + rhs.portable());
template<std::size_t N2, std::size_t M2> friend constexpr bool operator==(const symbol_text& lhs, const symbol_text<N2, M2>& rhs) noexcept; template<std::size_t N2, std::size_t M2> friend constexpr auto operator<=>(const symbol_text& lhs, const symbol_text<N2, M2>& rhs) noexcept;
Let @ be the operator.
Effects: Equivalent to: return std::make_tuple(std::cref(lhs.utf8()), std::cref(lhs.portable())) @ std::make_tuple(std::cref(rhs.utf8()), std::cref(rhs.portable()));