Add C string types

This commit is contained in:
Lander Gallastegi 2024-10-01 21:09:06 +02:00
parent 3dea1a9f81
commit 8d930b4e88

View file

@ -81,28 +81,28 @@ public:
return std::basic_string_view<T>{data};
}
char* begin() {
T* begin() {
if (this == nullptr) {
return nullptr;
}
return data;
}
const char* begin() const {
const T* begin() const {
if (this == nullptr) {
return nullptr;
}
return data;
}
char* end() {
T* end() {
if (this == nullptr) {
return nullptr;
}
return data + N;
}
const char* end() const {
const T* end() const {
if (this == nullptr) {
return nullptr;
}
@ -152,6 +152,24 @@ public:
static_assert(sizeof(CString<13>) == sizeof(char[13])); // Ensure size still matches a simple array
static_assert(std::weakly_incrementable<CString<13>::Iterator>);
/**
* @brief A null-terminated wide string with a fixed maximum length
* This class is not meant to be used as a general-purpose string class
* It is meant to be used as `char[N]` where memory layout is fixed
* @tparam N Maximum length of the string
*/
template <size_t N>
using CWString = CString<N, wchar_t>;
/**
* @brief A null-terminated 16-bit char string with a fixed maximum length
* This class is not meant to be used as a general-purpose string class
* It is meant to be used as `char[N]` where memory layout is fixed
* @tparam N Maximum length of the string
*/
template <size_t N>
using CU16String = CString<N, char16_t>;
#pragma clang diagnostic pop
} // namespace Common