diff --git a/m-variant.h b/m-variant.h index 8c4fb534..78eecb5e 100644 --- a/m-variant.h +++ b/m-variant.h @@ -39,6 +39,16 @@ M_END_PROTECTED_CODE +/* Define the variant type and functions + as the given name_t + USAGE: + VARIANT_DEF2_AS(name, name_t, [(field1, type1, oplist1), (field2, type2, oplist2), ...] ) */ +#define VARIANT_DEF2_AS(name, name_t, ...) \ + M_BEGIN_PROTECTED_CODE \ + VARIANTI_DEF2_P1( (name, name_t VARIANTI_INJECT_GLOBAL(__VA_ARGS__)) ) \ + M_END_PROTECTED_CODE + + /* Define the oplist of a variant. USAGE: VARIANT_OPLIST(name[, oplist of the first type, ...]) */ #define VARIANT_OPLIST(...) \ diff --git a/tests/test-mvariant.c b/tests/test-mvariant.c index 30a79aca..852383a3 100644 --- a/tests/test-mvariant.c +++ b/tests/test-mvariant.c @@ -58,6 +58,8 @@ VARIANT_DEF2(rvariant2, (name, string_t), (value, int)) VARIANT_DEF2(rvariant3, (name, string_t), (ivariant2, rvariant2_t), (ivariant, rvariant_t) ) +VARIANT_DEF2_AS(vector, Vector, (x, double), (y, double) ) +#define M_OPL_Vector() VARIANT_OPLIST(vector, M_DEFAULT_OPLIST) static void test_pair(void) { @@ -273,11 +275,19 @@ test_io(void) } } +static void test_double (void) +{ + M_LET(v, Vector) { + assert (vector_empty_p(v) ); + } +} + int main(void) { test_pair(); test_triple(); test_io(); + test_double(); exit(0); }