Derive-C
Loading...
Searching...
No Matches
require.h
Go to the documentation of this file.
1#pragma once
4
5#if defined DC_GENERIC_KEYWORD_SUPPORTED
6 #define DC_REQUIRE_METHOD_EXPR(ret, obj, name, args) \
7 _Generic(NS(obj, name), ret(*) args: 1, default: 0)
8 #define DC_REQUIRE_CONSTANT_TYPE_EXPR(obj, name, Type) \
9 _Generic((NS(obj, name)), Type: 1, default: 0)
10#else
11 #include <type_traits> // NOLINT(misc-include-cleaner)
12 #define DC_REQUIRE_METHOD_EXPR(ret, obj, name, args) \
13 std::is_same_v<decltype(+NS(obj, name)), ret(*) args>
14 #define DC_REQUIRE_CONSTANT_TYPE_EXPR(obj, name, Type) \
15 std::is_same_v<std::remove_cv_t<std::remove_reference_t<decltype(NS(obj, name))>>, Type>
16#endif
17
18#define DC_REQUIRE_METHOD(ret, obj, name, args) \
19 DC_STATIC_ASSERT(DC_REQUIRE_METHOD_EXPR(ret, obj, name, args), \
20 "Method " #obj "." #name " must exist with type " #ret " (*)" #args)
21
22// JUSTIFY: +1 on sizeof
23// - We use the sizeof to enforce the type exists
24// - For zero sized types, we need the expression to not be zero.
25#define DC_REQUIRE_TYPE(obj, name) DC_STATIC_ASSERT(sizeof(NS(obj, name)) + 1)
26
27#define DC_REQUIRE_CONSTANT(obj, name, type) \
28 DC_STATIC_ASSERT(DC_REQUIRE_CONSTANT_TYPE_EXPR(obj, name, type), \
29 "Method " #obj "." #name " must exist and be of type " #type)