Add macro TUPLE_DEF2_AS

This commit is contained in:
Patrick Pelissier committed 2020-10-03 14:07:14 +02:00
1 parent feb8b30048
commit 5b89196cd7
2 files changed
+23

No files matched your search

+10
View File
@@ -38,6 +38,16 @@
M_END_PROTECTED_CODE
/* Define the tuple type and functions
as the given name.
USAGE:
TUPLE_DEF2_AS(name, name_t, [(field1, type1[, oplist1]), (field2, type2[, oplist2]), ...] ) */
#define TUPLE_DEF2_AS(name, name_t, ...) \
M_BEGIN_PROTECTED_CODE \
TUPLEI_DEF2_P1( (name, name_t TUPLEI_INJECT_GLOBAL(__VA_ARGS__)) ) \
M_END_PROTECTED_CODE
/* Define the oplist of a tuple.
USAGE: TUPLE_OPLIST(name[, oplist of the first type, ...]) */
#define TUPLE_OPLIST(...) \
+13
View File
@@ -81,6 +81,9 @@ TUPLE_DEF2(rtuple3, (name, string_t), (ituple2, rtuple2_t), (ituple, rtuple_t) )
TUPLE_DEF2(rtuple4, (value, rtuple3_t) )
#define M_OPL_rtuple4_t() TUPLE_OPLIST(rtuple4, M_OPL_rtuple4_t() )
TUPLE_DEF2_AS(vector, Vector, (x, double), (y, double), (z, double) )
#define M_OPL_Vector() TUPLE_OPLIST(vector, M_DEFAULT_OPLIST )
static void check_swap(void)
{
pair_str_t p1, p2;
@@ -214,6 +217,15 @@ static void check_chaining_tuple(void)
rtuple4_clear(r);
}
static void test_double(void)
{
M_LET( (v, 1.0, 2.0, 3.0), Vector ) {
assert (*vector_cget_at_x(v) == 1.0 );
assert (*vector_cget_at_y(v) == 2.0 );
assert (*vector_cget_at_z(v) == 3.0 );
}
}
int main(void)
{
test1();
@@ -221,5 +233,6 @@ int main(void)
check_swap();
check_clean();
check_chaining_tuple();
test_double();
exit(0);
}