concepts: add the null_stringy concept

This commit is contained in:
Danny Robson 2022-06-20 09:30:45 +10:00
parent b54403557e
commit 85bd599577
1 changed files with 23 additions and 1 deletions

View File

@ -13,11 +13,33 @@
#include <string_view>
namespace cruft::concepts {
/// A literal c-string character array.
template <typename T>
concept c_string =
std::is_array_v<std::remove_cvref_t<T>> and
std::is_same_v<
std::remove_cvref_t<
std::remove_all_extents_t<
std::remove_cvref_t<T>
>
>,
char
>;
/// A type that behaves like a string. ie, a sequence of characters
template <typename T>
concept stringy =
std::same_as<T, std::string> or
std::same_as<T, std::string_view> or
std::same_as<T, char const*> or
std::same_as<T, char *>;
std::same_as<T, char *> or
c_string<T>;
/// A type that behaves like a string _and_ has a null terminator
template <typename T>
concept null_stringy =
std::same_as<T, std::string> or
std::same_as<T, char const*> or
std::same_as<T, char *>;
}