1#ifndef QX_STRINGLITERAL_H
2#define QX_STRINGLITERAL_H
9#include <QLatin1String>
23template<std::
integral C>
24class StringLiteralBase {};
26template<
typename O,
size_t N1,
size_t N2>
27constexpr auto concatNewStringLiteral(
const typename O::data_t (&a)[N1],
const typename O::data_t (&b)[N2])
29 using C =
typename O::data_t;
30 constexpr size_t L1 = N1 - 1;
31 constexpr size_t return_n = N1 + N2 - 1;
32 using result_t =
typename O::template rebind<return_n>;
42 std::copy_n(a, L1, buff);
43 std::copy_n(b, N2, buff + L1);
44 return result_t(buff);
57template<
typename T,
typename U>
61 std::same_as<typename T::data_t, typename U::data_t>;
63template<std::
integral C,
size_t N>
70 std::is_same_v<C, char>,
73 std::is_same_v<C, char16_t>,
85 static constexpr size_t size_v = N - 1;
95 constexpr StringLiteral(
const C (&str)[N]) { std::copy_n(str, N, _str); }
99 constexpr C*
data()
const {
return _str; }
100 constexpr size_t size()
const {
return N - 1; }
102 constexpr std::basic_string_view<C>
std_view()
const {
return std::basic_string_view<C>(*
this); }
108 constexpr operator QLatin1StringView() const requires std::same_as<C,
char> {
return QLatin1StringView(_str, N - 1); }
109 constexpr operator QStringView() const requires std::same_as<C,
char16_t > {
return QStringView(_str, N - 1); }
110 constexpr operator std::basic_string_view<C>()
const {
return std::basic_string_view<C>(_str, N - 1); }
119template<
typename StringLiteralA,
typename StringLiteralB>
120 requires compatible_string_literals<StringLiteralA, StringLiteralB>
121constexpr auto operator+(
const StringLiteralA& a,
const StringLiteralA& b)
123 return _QxPrivate::concatNewStringLiteral<StringLiteralA>(a._str, b._str);
132template<
string_literal S,
size_t N2>
133constexpr auto operator+(
const S& a,
const typename S::data_t (&b)[N2])
135 return _QxPrivate::concatNewStringLiteral<S>(a._str, b);
144template<
size_t N1,
string_literal S>
145constexpr auto operator+(
const typename S::data_t (&a)[N1],
const S& b)
147 return _QxPrivate::concatNewStringLiteral<S>(a, b._str);
156template<
string_literal S>
165template<
string_literal S>
std::conditional_t< std::is_same_v< C, char >, QLatin1StringView, std::conditional_t< std::is_same_v< C, char16_t >, QStringView, void > > view_t
Definition qx-stringliteral.h:69
constexpr auto operator+(const S &a, typename S::data_t b)
Definition qx-stringliteral.h:157
constexpr bool operator==(const StringLiteral &other) const =default
static constexpr size_t size_v
Definition qx-stringliteral.h:85
constexpr auto operator+(typename S::data_t a, const S &b)
Definition qx-stringliteral.h:166
constexpr size_t size() const
Definition qx-stringliteral.h:100
constexpr std::basic_string_view< C > std_view() const
Definition qx-stringliteral.h:102
constexpr C * data() const
Definition qx-stringliteral.h:99
constexpr auto operator+(const StringLiteralA &a, const StringLiteralA &b)
Definition qx-stringliteral.h:121
constexpr view_t view() const
Definition qx-stringliteral.h:101
constexpr std::strong_ordering operator<=>(const StringLiteral &other) const =default
constexpr StringLiteral(const C(&str)[N])
Definition qx-stringliteral.h:95
C data_t
Definition qx-stringliteral.h:68
constexpr auto operator+(const typename S::data_t(&a)[N1], const S &b)
Definition qx-stringliteral.h:145
constexpr auto operator+(const S &a, const typename S::data_t(&b)[N2])
Definition qx-stringliteral.h:133
Specifies that two types are StringLiterals that use the same storage type.
Definition qx-stringliteral.h:58
Specifies that a type is a derivation of any specialization of a template.
Definition qx-concepts.h:516
Specifies that a type is a specialization or derivation of StringLiteral.
Definition qx-stringliteral.h:55
The Qx namespace is the main namespace through which all non-global functionality of the Qx library i...
Definition qx-abstracterror.cpp:13
The qx-concepts header file provides a library of general purpose concepts as an extension of the sta...
CStringLiteral acts like a typedef/alias for a StringLiteral that uses char as its storage type.
Definition qx-stringliteral.h:194
constexpr CStringLiteral(const char(&str)[N])
Definition qx-stringliteral.h:195
U16StringLiteral acts like a typedef/alias for a StringLiteral that uses char16_t as its storage type...
Definition qx-stringliteral.h:215
constexpr U16StringLiteral(const char16_t(&str)[N])
Definition qx-stringliteral.h:216
U32StringLiteral acts like a typedef/alias for a StringLiteral that uses char32_t as its storage type...
Definition qx-stringliteral.h:222
constexpr U32StringLiteral(const char32_t(&str)[N])
Definition qx-stringliteral.h:223
U8StringLiteral acts like a typedef/alias for a StringLiteral that uses char8_t as its storage type.
Definition qx-stringliteral.h:208
constexpr U8StringLiteral(const char8_t(&str)[N])
Definition qx-stringliteral.h:209
WStringLiteral acts like a typedef/alias for a StringLiteral that uses wchar_t as its storage type.
Definition qx-stringliteral.h:201
constexpr WStringLiteral(const wchar_t(&str)[N])
Definition qx-stringliteral.h:202