includes/type: Added magic number assertion type

This commit is contained in:
Nik
2022-11-29 14:43:27 +01:00
committed by GitHub
parent 9887da7af5
commit 110b498d7b

19
includes/type/magic.pat Normal file
View File

@@ -0,0 +1,19 @@
#include <std/string.pat>
#include <std/sys.pat>
namespace type {
struct Magic<auto ExpectedValue> {
char value[std::string::length(ExpectedValue)];
std::assert(value == ExpectedValue, std::format("Invalid magic value! Expected \"{}\", got \"{}\".", ExpectedValue, value));
} [[sealed, format("type::impl::format_magic")]];
namespace impl {
fn format_magic(ref auto magic) {
return magic.value;
};
}
}