Derive-C
Loading...
Searching...
No Matches
eq.h
Go to the documentation of this file.
1
3#pragma once
4
5#include <stdbool.h>
6#include <string.h>
7
12
13#define DC_TRAIT_EQABLE(SELF) DC_REQUIRE_METHOD(bool, SELF, eq, (SELF const*, SELF const*))
14
15#define DC_TRAIT_EQABLE_INVARIANTS(SELF, a, b) \
16 DC_TRAIT_EQABLE(SELF); \
17 DC_ASSUME(DC_WHEN(NS(SELF, eq)(&a, &b) && NS(SELF, eq)(&b, &c), NS(SELF, eq)(&a, &c))); \
18 DC_ASSUME(DC_WHEN(NS(SELF, eq)(&a, &b), NS(SELF, eq)(&b, &a))); \
19 DC_ASSUME(NS(SELF, eq)(&a, &a))
20
21#define DC_MEM_EQ(SELF_1, SELF_2) (*(SELF_1) == *(SELF_2))
22
23#define _DC_DERIVE_EQ_MEMBER(MEMBER_TYPE, MEMBER_NAME) \
24 &&NS(MEMBER_TYPE, eq)(&self_1->MEMBER_NAME, &self_2->MEMBER_NAME)
25
26#define DC_DERIVE_EQ(TYPE) \
27 DC_PUBLIC static bool NS(TYPE, eq)(TYPE const* self_1, TYPE const* self_2) { \
28 return true NS(TYPE, REFLECT)(_DC_DERIVE_EQ_MEMBER); \
29 }
30
31#define _DC_DERIVE_STD_EQ(TYPE, ...) \
32 DC_PUBLIC static DC_UNUSED bool NS(TYPE, eq)(TYPE const* self_1, TYPE const* self_2) { \
33 return (*self_1 == *self_2); \
34 }
35
37
38DC_PUBLIC static bool dc_str_eq(char* const* self_1, char* const* self_2) {
39 return strcmp(*self_1, *self_2) == 0;
40}
41
42DC_PUBLIC static bool dc_str_const_eq(const char* const* self_1, const char* const* self_2) {
43 return strcmp(*self_1, *self_2) == 0;
44}
#define _DC_DERIVE_STD_EQ(TYPE,...)
Definition eq.h:31
static DC_PUBLIC bool dc_str_const_eq(const char *const *self_1, const char *const *self_2)
Definition eq.h:42
static DC_PUBLIC bool dc_str_eq(char *const *self_1, char *const *self_2)
Definition eq.h:38
#define DC_PUBLIC
Definition namespace.h:25
#define DC_STD_REFLECT(F,...)
Definition reflect.h:32