Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#define STRUCTEQ_SAFE(t, ...) \
static inline bool structeq_##t(const struct t *a, const struct t *b) \
{ \
return CPPMAGIC_JOIN(&&, STRUCTEQ_MAP2(STRUCTEQ_MEMBEREQ_, t, __VA_ARGS__)); \
}
#define STRUCTEQ_MEMBEREQ_(t, m) \
(memcmp(&a->m, &b->m, sizeof(a->m)) == 0)
/* Stolen from cppmagic, but with a extra arg added. */
#define _STRUCTEQ_MAP2_() _STRUCTEQ_MAP2
#define _STRUCTEQ_MAP2(m_, a1_, a_, ...) \
m_(a1_, a_) \
CPPMAGIC_IFELSE(CPPMAGIC_NONEMPTY(__VA_ARGS__)) \
(, CPPMAGIC_DEFER2(_STRUCTEQ_MAP2_)()(m_, a1_, __VA_ARGS__)) \
()
#define STRUCTEQ_MAP2(m_, a1_, ...) \
CPPMAGIC_IFELSE(CPPMAGIC_NONEMPTY(__VA_ARGS__)) \
(CPPMAGIC_EVAL(_STRUCTEQ_MAP2(m_, a1_, __VA_ARGS__))) \
()
#include <stdint.h>
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <ccan/structeq/structeq.h>
struct short_channel_id {
uint16_t outnum;
uint64_t blocknum;
uint32_t txnum;
};
STRUCTEQ_MAP2(STRUCTEQ_MEMBEREQ_, t, a, b)
//CPPMAGIC_JOIN(&&, 1, STRUCTEQ_MAP2(STRUCTEQ_MEMBEREQ_, t, a, b))
//STRUCTEQ_SAFE(short_channel_id, outnum, blocknum, txnum);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment