From 142b2e2e141e43e2ff65207846ba86ed563a4cc3 Mon Sep 17 00:00:00 2001 From: Faumaray Date: Mon, 20 Oct 2025 00:53:04 +0300 Subject: [PATCH] enforce ctx in constructor Signed-off-by: Faumaray --- include/Mod/Mod.hpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/include/Mod/Mod.hpp b/include/Mod/Mod.hpp index c222602..eabef58 100644 --- a/include/Mod/Mod.hpp +++ b/include/Mod/Mod.hpp @@ -15,21 +15,28 @@ namespace vl::mod { #endif // detection helpers -template -concept HasCtorWithContext = - std::is_constructible_v; +template +struct _has_ctor_ctx : std::false_type {}; -template +template +struct _has_ctor_ctx()))>> : std::true_type {}; + +template +inline constexpr bool has_ctor_ctx_v = _has_ctor_ctx::value; + +// -------- Detection: T must provide Name()/Version() returning std::string_view (SV1) -------- +template concept HasStaticName = requires { { T::Name() } -> std::same_as; }; -template +template concept HasStaticVersion = requires { { T::Version() } -> std::same_as; }; template class Mod : public Base { - static_assert(HasCtorWithContext, + // Compile-time contract: + static_assert(has_ctor_ctx_v, "Any class derived from Mod must have a constructor: T(const vl::log::Context&)"); static_assert(HasStaticName, "Any class derived from Mod must declare: static constexpr std::string_view Name()");