enforce ctx in constructor
Signed-off-by: Faumaray <faumaray@gmail.com>
This commit is contained in:
1 file changed
+13
-6
+13
-6
@@ -15,21 +15,28 @@ namespace vl::mod {
|
||||
#endif
|
||||
|
||||
// detection helpers
|
||||
template <class T>
|
||||
concept HasCtorWithContext =
|
||||
std::is_constructible_v<T, const Context&>;
|
||||
template<class X, class = void>
|
||||
struct _has_ctor_ctx : std::false_type {};
|
||||
|
||||
template <class T>
|
||||
template<class X>
|
||||
struct _has_ctor_ctx<X, std::void_t<decltype(X(std::declval<const Context&>()))>> : std::true_type {};
|
||||
|
||||
template<class X>
|
||||
inline constexpr bool has_ctor_ctx_v = _has_ctor_ctx<X>::value;
|
||||
|
||||
// -------- Detection: T must provide Name()/Version() returning std::string_view (SV1) --------
|
||||
template<class T>
|
||||
concept HasStaticName =
|
||||
requires { { T::Name() } -> std::same_as<std::string_view>; };
|
||||
|
||||
template <class T>
|
||||
template<class T>
|
||||
concept HasStaticVersion =
|
||||
requires { { T::Version() } -> std::same_as<std::string_view>; };
|
||||
|
||||
template <class T>
|
||||
class Mod : public Base {
|
||||
static_assert(HasCtorWithContext<T>,
|
||||
// Compile-time contract:
|
||||
static_assert(has_ctor_ctx_v<T>,
|
||||
"Any class derived from Mod<T> must have a constructor: T(const vl::log::Context&)");
|
||||
static_assert(HasStaticName<T>,
|
||||
"Any class derived from Mod<T> must declare: static constexpr std::string_view Name()");
|
||||
|
||||
Reference in new issue
Block a user