#ifndef _UID_HPP #define _UID_HPP #include #include #include #include template class UID { public: std::array array; constexpr UID() : array({'\0'}) {} constexpr UID(std::string_view initializer) { for (typeof(len) it = 0; it != len; it++) { array[it] = *(initializer.begin() + it); } //array[len] = '\0'; } constexpr UID(const char *initializer) { *this = UID(std::string_view{initializer, len}); } constexpr bool has_value() const { return array[0] != '\0'; } constexpr std::string_view str() const { if (has_value()) { return {array.begin(), static_cast(len)}; } else { return "NUL_V"; } } }; constexpr int SUID_len = 3; constexpr int UUID_len = 9; using SUID = UID; using UUID = UID; struct AnyUID { std::variant id; enum Type { USER, SERVER, OTHER, NUL } type = NUL; std::string_view str() const { if (type == SERVER) { return std::get(id).str(); } else if (type == USER) { return std::get(id).str(); } else if (type == OTHER) { return std::get(id); } else { return "NUL_T"; } } auto operator =(const SUID& val) { type = SERVER; id = val; } auto operator =(const UUID& val) { type = USER; id = val; } auto operator =(const std::string& val) { type = OTHER; id = std::string(val); } auto operator =(std::nullptr_t) { type = NUL; id = nullptr; } AnyUID() {} template AnyUID(const T& val) { *this = val; } }; #endif