From 110b498d7b2148494f8d52b043ab148f44c8d082 Mon Sep 17 00:00:00 2001 From: Nik Date: Tue, 29 Nov 2022 14:43:27 +0100 Subject: [PATCH] includes/type: Added magic number assertion type --- includes/type/magic.pat | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 includes/type/magic.pat diff --git a/includes/type/magic.pat b/includes/type/magic.pat new file mode 100644 index 0000000..22d0392 --- /dev/null +++ b/includes/type/magic.pat @@ -0,0 +1,19 @@ +#include +#include + +namespace type { + + struct Magic { + 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; + }; + + } + +}