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_FUNCTION(ret, func, args) _Generic(func, ret(*) args: 1, default: 0)
7 #define DC_REQUIRE_CONSTANT_TYPE_EXPR(obj, name, Type) \
8 _Generic((NS(obj, name)), Type: 1, default: 0)
9#else
10 #include <type_traits> // NOLINT(misc-include-cleaner)
11 #define DC_REQUIRE_FUNCTION(ret, func, args) std::is_same_v<decltype(+func), ret(*) args>
12 #define DC_REQUIRE_CONSTANT_TYPE_EXPR(obj, name, Type) \
13 std::is_same_v<std::remove_cv_t<std::remove_reference_t<decltype(NS(obj, name))>>, Type>
14#endif
15
16#define DC_REQUIRE_METHOD(ret, obj, name, args) \
17 DC_STATIC_ASSERT(DC_REQUIRE_FUNCTION(ret, NS(obj, name), args), \
18 "Method " #obj "." #name " must exist with type " #ret " (*)" #args)
19
20// JUSTIFY: +1 on sizeof
21// - We use the sizeof to enforce the type exists
22// - For zero sized types, we need the expression to not be zero.
23#define DC_REQUIRE_TYPE(obj, name) DC_STATIC_ASSERT(sizeof(NS(obj, name)) + 1)
24
25#define DC_REQUIRE_CONSTANT(obj, name, type) \
26 DC_STATIC_ASSERT(DC_REQUIRE_CONSTANT_TYPE_EXPR(obj, name, type), \
27 "Method " #obj "." #name " must exist and be of type " #type)