Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <stdbool.h>
- #include <stdint.h>
- #include <assert.h>
- #ifdef __clang__
- #define auto __auto_type
- #endif
- #define TEST(...) TA(__VA_OPT__(T), (__VA_OPT__(__VA_ARGS__)))
- #define TA(X,Y) T##X Y
- #define T(...) false
- #define TT(...) true
- #define COUNT_ARGS(...) CA0P(__VA_OPT__(T), (__VA_OPT__(__VA_ARGS__)))
- #define CA0P(X,Y) CA0T##X Y
- #define CA0T(...) 0
- #define CA0TT(X,...) CA1(__VA_ARGS__)
- #define CA1(...) CA1P(__VA_OPT__(T), (__VA_OPT__(__VA_ARGS__)))
- #define CA1P(X,Y) CA1T##X Y
- #define CA1T(...) 1
- #define CA1TT(X,...) CA2(__VA_ARGS__)
- #define CA2(...) CA2P(__VA_OPT__(T), (__VA_OPT__(__VA_ARGS__)))
- #define CA2P(X,Y) CA2T##X Y
- #define CA2T(...) 2
- #define CA2TT(X,...) CA3(__VA_ARGS__)
- #define CA3(...) CA3P(__VA_OPT__(T), (__VA_OPT__(__VA_ARGS__)))
- #define CA3P(X,Y) CA3T##X Y
- #define CA3T(...) 3
- #define CA3TT(X,...) CA4(__VA_ARGS__)
- #define CA4(...) CA4P(__VA_OPT__(T), (__VA_OPT__(__VA_ARGS__)))
- #define CA4P(X,Y) CA4T##X Y
- #define CA4T(...) 4
- #define CA4TT(X,...) CA5(__VA_ARGS__)
- #define CA5(...) CA5P(__VA_OPT__(T), (__VA_OPT__(__VA_ARGS__)))
- #define CA5P(X,Y) CA5T##X Y
- #define CA5T(...) 5
- #define CA5TT(X,...) CA6(__VA_ARGS__)
- #define CA6(...) CA6P(__VA_OPT__(T), (__VA_OPT__(__VA_ARGS__)))
- #define CA6P(X,Y) CA6T##X Y
- #define CA6T(...) 6
- #define CA6TT(X,...) CA7(__VA_ARGS__)
- #define CA7(...) CA7P(__VA_OPT__(T), (__VA_OPT__(__VA_ARGS__)))
- #define CA7P(X,Y) CA7T##X Y
- #define CA7T(...) 7
- #define CA7TT(X,...) CA8(__VA_ARGS__)
- #define CA8(...) CA8P(__VA_OPT__(T), (__VA_OPT__(__VA_ARGS__)))
- #define CA8P(X,Y) CA8T##X Y
- #define CA8T(...) 8
- #define CA8TT(X,...) CA9(__VA_ARGS__)
- #define CA9(...) CA9P(__VA_OPT__(T), (__VA_OPT__(__VA_ARGS__)))
- #define CA9P(X,Y) CA9T##X Y
- #define CA9T(...) 9
- #define CA9TT(X,...) CA10(__VA_ARGS__)
- #define CA10(...) CA10P(__VA_OPT__(T), (__VA_OPT__(__VA_ARGS__)))
- #define CA10P(X,Y) CA10T##X Y
- #define CA10T(...) 10
- #define CA10TT(X,...) CA11(__VA_ARGS__)
- #define CA11(...) CA11P(__VA_OPT__(T), (__VA_OPT__(__VA_ARGS__)))
- #define CA11P(X,Y) CA11T##X Y
- #define CA11T(...) 11
- #define CA11TT(X,...) CA12(__VA_ARGS__)
- #define CA12(...) CA12P(__VA_OPT__(T), (__VA_OPT__(__VA_ARGS__)))
- #define CA12P(X,Y) CA12T##X Y
- #define CA12T(...) 12
- #define CA12TT(X,...) CA13(__VA_ARGS__)
- #define CA13(...) CA13P(__VA_OPT__(T), (__VA_OPT__(__VA_ARGS__)))
- #define CA13P(X,Y) CA13T##X Y
- #define CA13T(...) 13
- #define CA13TT(X,...) CA14(__VA_ARGS__)
- #define CA14(...) CA14P(__VA_OPT__(T), (__VA_OPT__(__VA_ARGS__)))
- #define CA14P(X,Y) CA14T##X Y
- #define CA14T(...) 14
- #define CA14TT(X,...) CA15(__VA_ARGS__)
- #define CA15(...) CA15P(__VA_OPT__(T), (__VA_OPT__(__VA_ARGS__)))
- #define CA15P(X,Y) CA15T##X Y
- #define CA15T(...) 15
- #define CA15TT(X,...) CA16(__VA_ARGS__)
- #define CA16(...) CA16P(__VA_OPT__(T), (__VA_OPT__(__VA_ARGS__)))
- #define CA16P(X,Y) CA16T##X Y
- #define CA16T(...) 16
- #define CA16TT(X,...) CA17(__VA_ARGS__)
- #define UNWRAP(...) __VA_ARGS__
- #define FMAP(F,X) FMAP_EX(COUNT_ARGS X, F, UNWRAP X)
- #define FMAP_EX(C,F,...) FMAP_EX1(C, F __VA_OPT__(,) __VA_ARGS__)
- #define FMAP_EX1(C,F,...) FMAP##C(F __VA_OPT__(,) __VA_ARGS__)
- #define FMAP0(F) ()
- #define FMAP1(F,A0) (F(A0))
- #define FMAP2(F,A0,A1) (F(A0),F(A1))
- #define FMAP3(F,A0,A1,A2) (F(A0),F(A1),F(A2))
- #define FMAP4(F,A0,A1,A2,A3) (F(A0),F(A1),F(A2),F(A3))
- #define FMAP5(F,A0,A1,A2,A3,A4) (F(A0),F(A1),F(A2),F(A3),F(A4))
- #define FMAP6(F,A0,A1,A2,A3,A4,A5) \
- (F(A0),F(A1),F(A2),F(A3),F(A4),F(A5))
- #define FMAP7(F,A0,A1,A2,A3,A4,A5,A6) \
- (F(A0),F(A1),F(A2),F(A3),F(A4),F(A5),\
- F(A6))
- #define FMAP8(F,A0,A1,A2,A3,A4,A5,A6,A7) \
- (F(A0),F(A1),F(A2),F(A3),F(A4),F(A5),\
- F(A6),F(A7))
- #define FMAP9(F,A0,A1,A2,A3,A4,A5,A6,A7,A8) \
- (F(A0),F(A1),F(A2),F(A3),F(A4),F(A5),\
- F(A6),F(A7),F(A8))
- #define FMAP10(F,A0,A1,A2,A3,A4,A5,A6,A7,A8,A9) \
- (F(A0),F(A1),F(A2),F(A3),F(A4),F(A5),\
- F(A6),F(A7),F(A8),F(A9))
- #define FMAP11(F,A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10) \
- (F(A0),F(A1),F(A2),F(A3),F(A4),F(A5),\
- F(A6),F(A7),F(A8),F(A9),F(A10))
- #define FMAP12(F,A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11) \
- (F(A0),F(A1),F(A2),F(A3),F(A4),F(A5),\
- F(A6),F(A7),F(A8),F(A9),F(A10),F(A11))
- #define FMAP13(F,A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12) \
- (F(A0),F(A1),F(A2),F(A3),F(A4),F(A5),\
- F(A6),F(A7),F(A8),F(A9),F(A10),F(A11),\
- F(A12))
- #define FMAP14(F,A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13) \
- (F(A0),F(A1),F(A2),F(A3),F(A4),F(A5),\
- F(A6),F(A7),F(A8),F(A9),F(A10),F(A11),\
- F(A12),F(A13))
- #define FMAP15(F,A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14) \
- (F(A0),F(A1),F(A2),F(A3),F(A4),F(A5),\
- F(A6),F(A7),F(A8),F(A9),F(A10),F(A11),\
- F(A12),F(A13),F(A14))
- #define FMAP16(F,A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15) \
- (F(A0),F(A1),F(A2),F(A3),F(A4),F(A5),\
- F(A6),F(A7),F(A8),F(A9),F(A10),F(A11),\
- F(A12),F(A13),F(A14),F(A15))
- #define gtuple(...) (tupletypeof(__VA_ARGS__)) tuple(__VA_ARGS__)
- #define deftuple(VAR,TUP) tupletypeof TUP VAR = tuple TUP
- typedef struct tuple_len0 {} tuple_len0;
- typedef struct tuple_len1 {} tuple_len1;
- typedef struct tuple_len2 {} tuple_len2;
- typedef struct tuple_len3 {} tuple_len3;
- typedef struct tuple_len4 {} tuple_len4;
- typedef struct tuple_len5 {} tuple_len5;
- typedef struct tuple_len6 {} tuple_len6;
- typedef struct tuple_len7 {} tuple_len7;
- typedef struct tuple_len8 {} tuple_len8;
- typedef struct tuple_len9 {} tuple_len9;
- typedef struct tuple_len10 {} tuple_len10;
- typedef struct tuple_len11 {} tuple_len11;
- typedef struct tuple_len12 {} tuple_len12;
- typedef struct tuple_len13 {} tuple_len13;
- typedef struct tuple_len14 {} tuple_len14;
- typedef struct tuple_len15 {} tuple_len15;
- typedef struct tuple_len16 {} tuple_len16;
- typedef struct tuple_empty {} tuple_empty;
- typedef struct tuple0 {
- tuple_empty p0;
- tuple_empty p1;
- tuple_empty p2;
- tuple_empty p3;
- tuple_empty p4;
- tuple_empty p5;
- tuple_empty p6;
- tuple_empty p7;
- tuple_empty p8;
- tuple_empty p9;
- tuple_empty p10;
- tuple_empty p11;
- tuple_empty p12;
- tuple_empty p13;
- tuple_empty p14;
- tuple_empty p15;
- tuple_len0 len;
- } tuple0;
- #define tuple(...) TUPLE_EX(COUNT_ARGS(__VA_ARGS__), (__VA_ARGS__))
- #define TUPLE_EX(X,Y) TUPLE_EX1(X,Y)
- #define TUPLE_EX1(X,Y) TUPLE##X Y
- #define TUPLE0() {{}}
- #define TUPLE1(P0) {P0,{}}
- #define TUPLE2(P0,P1) {P0,P1,{}}
- #define TUPLE3(P0,P1,P2) {P0,P1,P2,{}}
- #define TUPLE4(P0,P1,P2,P3) {P0,P1,P2,P3,{}}
- #define TUPLE5(P0,P1,P2,P3,P4) {P0,P1,P2,P3,P4,{}}
- #define TUPLE6(P0,P1,P2,P3,P4,P5) {P0,P1,P2,P3,P4,P5,{}}
- #define TUPLE7(P0,P1,P2,P3,P4,P5,P6) {P0,P1,P2,P3,P4,P5,P6,{}}
- #define TUPLE8(P0,P1,P2,P3,P4,P5,P6,P7) {P0,P1,P2,P3,P4,P5,P6,P7,{}}
- #define TUPLE9(P0,P1,P2,P3,P4,P5,P6,P7,P8) {P0,P1,P2,P3,P4,P5,P6,P7,P8,{}}
- #define TUPLE10(P0,P1,P2,P3,P4,P5,P6,P7,P8,P9) \
- {P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,{}}
- #define TUPLE11(P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10) \
- {P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,{}}
- #define TUPLE12(P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11) \
- {P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,{}}
- #define TUPLE13(P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12) \
- {P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,{}}
- #define TUPLE14(P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13) \
- {P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,{}}
- #define TUPLE15(P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14) \
- {P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14,{}}
- #define TUPLE16(P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14,P15) \
- {P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14,P15,{}}
- #define tupletypeof(...) TUPLETYPEOF_EX(FMAP(typeof, (__VA_ARGS__)))
- #define TUPLETYPEOF_EX(TUP) TUPLETYPEOF_EX1(TUP)
- #define TUPLETYPEOF_EX1(TUP) tuple_t TUP
- #define _TUPLETYPE_EX(X,Y) TUPLETYPE_EX1(X,Y)
- #define _TUPLETYPE_EX1(X,Y) TUPLETYPE##X Y
- typedef void* tuple_t;
- #define tuple_t(...) TUPLE_T_EX(COUNT_ARGS(__VA_ARGS__), (__VA_ARGS__))
- #define TUPLE_T_EX(X,Y) TUPLE_T_EX1(X,Y)
- #define TUPLE_T_EX1(X,Y) TUPLE_T##X Y
- #define TUPLE_T0() tuple0
- #define TUPLE_T1(P0) \
- struct {P0 p0; tuple_len1 len;\
- tuple_empty p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15; }
- #define TUPLE_T2(P0,P1) \
- struct {P0 p0; P1 p1; tuple_len2 len;\
- tuple_empty p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15; }
- #define TUPLE_T3(P0,P1,P2) \
- struct {P0 p0; P1 p1; P2 p2; tuple_len3 len;\
- tuple_empty p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15; }
- #define TUPLE_T4(P0,P1,P2,P3) \
- struct {P0 p0; P1 p1; P2 p2; P3 p3; tuple_len4 len;\
- tuple_empty p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15; }
- #define TUPLE_T5(P0,P1,P2,P3,P4) \
- struct {P0 p0; P1 p1; P2 p2; P3 p3; P4 p4; tuple_len5 len;\
- tuple_empty p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15; }
- #define TUPLE_T6(P0,P1,P2,P3,P4,P5) \
- struct {P0 p0; P1 p1; P2 p2; P3 p3; P4 p4; P5 p5; tuple_len6 len;\
- tuple_empty p6,p7,p8,p9,p10,p11,p12,p13,p14,p15; }
- #define TUPLE_T7(P0,P1,P2,P3,P4,P5,P6) \
- struct {P0 p0; P1 p1; P2 p2; P3 p3; P4 p4; P5 p5; P6 p6; tuple_len7 len;\
- tuple_empty p7,p8,p9,p10,p11,p12,p13,p14,p15; }
- #define TUPLE_T8(P0,P1,P2,P3,P4,P5,P6,P7) \
- struct {P0 p0; P1 p1; P2 p2; P3 p3; P4 p4; P5 p5; P6 p6; P7 p7; tuple_len8 len;\
- tuple_empty p8,p9,p10,p11,p12,p13,p14,p15; }
- #define TUPLE_T9(P0,P1,P2,P3,P4,P5,P6,P7,P8) \
- struct {P0 p0; P1 p1; P2 p2; P3 p3; P4 p4; P5 p5; P6 p6; P7 p7; P8 p8; tuple_len9 len;\
- tuple_empty p9,p10,p11,p12,p13,p14,p15; }
- #define TUPLE_T10(P0,P1,P2,P3,P4,P5,P6,P7,P8,P9) \
- struct {P0 p0; P1 p1; P2 p2; P3 p3; P4 p4; P5 p5; P6 p6; P7 p7; P8 p8; P9 p9; tuple_len10 len;\
- tuple_empty p10,p11,p12,p13,p14,p15; }
- #define TUPLE_T11(P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10) \
- struct {P0 p0; P1 p1; P2 p2; P3 p3; P4 p4;\
- P5 p5; P6 p6; P7 p7; P8 p8; P9 p9;\
- P10 p10; tuple_len11 len;\
- tuple_empty p11,p12,p13,p14,p15; }
- #define TUPLE_T12(P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11) \
- struct {P0 p0; P1 p1; P2 p2; P3 p3; P4 p4;\
- P5 p5; P6 p6; P7 p7; P8 p8; P9 p9;\
- P10 p10; P11 p11; tuple_len12 len;\
- tuple_empty p12,p13,p14,p15; }
- #define TUPLE_T13(P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12) \
- struct {P0 p0; P1 p1; P2 p2; P3 p3; P4 p4;\
- P5 p5; P6 p6; P7 p7; P8 p8; P9 p9;\
- P10 p10; P11 p11; P12 p12; tuple_len13 len;\
- tuple_empty p13,p14,p15; }
- #define TUPLE_T14(P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13) \
- struct {P0 p0; P1 p1; P2 p2; P3 p3; P4 p4;\
- P5 p5; P6 p6; P7 p7; P8 p8; P9 p9;\
- P10 p10; P11 p11; P12 p12; P13 p13; tuple_len14 len;\
- tuple_empty p14,p15; }
- #define TUPLE_T15(P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14) \
- struct {P0 p0; P1 p1; P2 p2; P3 p3; P4 p4;\
- P5 p5; P6 p6; P7 p7; P8 p8; P9 p9;\
- P10 p10; P11 p11; P12 p12; P13 p13; P14 p14; tuple_len15 len;\
- tuple_empty p15; }
- #define TUPLE_T16(P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14,P15) \
- struct {P0 p0; P1 p1; P2 p2; P3 p3; P4 p4;\
- P5 p5; P6 p6; P7 p7; P8 p8; P9 p9;\
- P10 p10; P11 p11; P12 p12; P13 p13; P14 p14;\
- P15 p15; tuple_len16 len;}
- typedef struct tuple_index0 {bool dummy;} tuple_index0;
- typedef struct tuple_index1 {bool dummy;} tuple_index1;
- typedef struct tuple_index2 {bool dummy;} tuple_index2;
- typedef struct tuple_index3 {bool dummy;} tuple_index3;
- typedef struct tuple_index4 {bool dummy;} tuple_index4;
- typedef struct tuple_index5 {bool dummy;} tuple_index5;
- typedef struct tuple_index6 {bool dummy;} tuple_index6;
- typedef struct tuple_index7 {bool dummy;} tuple_index7;
- typedef struct tuple_index8 {bool dummy;} tuple_index8;
- typedef struct tuple_index9 {bool dummy;} tuple_index9;
- typedef struct tuple_index10 {bool dummy;} tuple_index10;
- typedef struct tuple_index11 {bool dummy;} tuple_index11;
- typedef struct tuple_index12 {bool dummy;} tuple_index12;
- typedef struct tuple_index13 {bool dummy;} tuple_index13;
- typedef struct tuple_index14 {bool dummy;} tuple_index14;
- typedef struct tuple_index15 {bool dummy;} tuple_index15;
- #define settuple(VAR,TUP) VAR = (typeof(VAR))tuple TUP
- #define tuple_nth(TUP,INDEX) _Generic(((TUP).p##INDEX),\
- tuple_empty: tuple_index_error(tuplen(TUP), INDEX),\
- default: (TUP).p##INDEX\
- )
- #define print_tuple_nth(TUP,N) do {\
- auto _prtp_nth = tuple_nth(TUP,N);\
- printf(_Generic(_prtp_nth,\
- int: "%d",\
- long int: "%ld",\
- unsigned int: "%u",\
- long unsigned int: "%lu",\
- char*: "\"%s\"",\
- char: "%c",\
- float: "%f",\
- double: "%lf"), _prtp_nth);\
- } while (false)
- #define print_tuple(TUP) do {\
- size_t _prtp_len = tuplen(TUP);\
- printf("(");\
- if (tuplen(TUP) > 0) {\
- print_tuple_nth(TUP,0);\
- if (tuplen(TUP) > 1) {\
- printf(", ");\
- print_tuple_nth(TUP,1);\
- if (tuplen(TUP) > 2) {\
- printf(", ");\
- print_tuple_nth(TUP,2);\
- if (tuplen(TUP) > 3) {\
- printf(", ");\
- print_tuple_nth(TUP,3);\
- if (tuplen(TUP) > 4) {\
- printf(", ");\
- print_tuple_nth(TUP,4);\
- if (tuplen(TUP) > 5) {\
- printf(", ");\
- print_tuple_nth(TUP,5);\
- if (tuplen(TUP) > 6) {\
- printf(", ");\
- print_tuple_nth(TUP,6);\
- if (tuplen(TUP) > 7) {\
- printf(", ");\
- print_tuple_nth(TUP,7);\
- if (tuplen(TUP) > 8) {\
- printf(", ");\
- print_tuple_nth(TUP,8);\
- if (tuplen(TUP) > 9) {\
- printf(", ");\
- print_tuple_nth(TUP,9);\
- if (tuplen(TUP) > 10) {\
- printf(", ");\
- print_tuple_nth(TUP,10);\
- if (tuplen(TUP) > 11) {\
- printf(", ");\
- print_tuple_nth(TUP,11);\
- if (tuplen(TUP) > 12) {\
- printf(", ");\
- print_tuple_nth(TUP,12);\
- if (tuplen(TUP) > 13) {\
- printf(", ");\
- print_tuple_nth(TUP,13);\
- if (tuplen(TUP) > 14) {\
- printf(", ");\
- print_tuple_nth(TUP,14);\
- if (tuplen(TUP) > 15) {\
- printf(", ");\
- print_tuple_nth(TUP,15);\
- if (tuplen(TUP) > 16) {\
- printf(", ");\
- print_tuple_nth(TUP,15);\
- }\
- }\
- }\
- }\
- }\
- }\
- }\
- }\
- }\
- }\
- }\
- }\
- }\
- }\
- }\
- }\
- printf(")");\
- }\
- } while (false)
- #define tuplen(TUP) _Generic((TUP).len,\
- tuple_len0: 0,\
- tuple_len1: 1,\
- tuple_len2: 2,\
- tuple_len3: 3,\
- tuple_len4: 4,\
- tuple_len5: 5,\
- tuple_len6: 6,\
- tuple_len7: 7,\
- tuple_len8: 8,\
- tuple_len9: 9,\
- tuple_len10: 10,\
- tuple_len11: 11,\
- tuple_len12: 12,\
- tuple_len13: 13,\
- tuple_len14: 14,\
- tuple_len15: 15,\
- tuple_len16: 16\
- )
- float tuple_function(tuple_t x, tuple_t y) {
- tuple_t(int, float)* yp = (typeof(yp))y;
- return (float)yp->p0 + yp->p1;
- }
- void test() {
- tuple_t() x;
- tuple_t(int, float) y;
- settuple(x, ());
- settuple(y, (1, 1.0));
- assert(sizeof(x) == 0);
- assert(y.p0 == 1);
- assert(y.p1 == 1.0);
- assert(tuple_function((tuple_t)&x, (tuple_t)&y) == 2.0);
- int k[2] = {1,2};
- deftuple(t0, ());
- deftuple(t1, ("a"));
- deftuple(t2, (x, 2));
- deftuple(t3, (t0, t2, 0.0));
- deftuple(t4, ((int*)k,"abc",2500,t0));
- deftuple(t5, (1,2,3,4,5));
- deftuple(t6, ("a",2,3.0,'d',0x5,0b110));
- deftuple(t7, (1,2,3,4,5,6,7));
- deftuple(t8, (1,2,3,4,5,6,7,8));
- deftuple(t9, (1,2,3,4,5,6,7,8,9));
- deftuple(t10, (1,2,3,4,5,6,7,8,9,10));
- deftuple(t11, (1,2,3,4,5,6,7,8,9,10,11));
- deftuple(t12, (1,2,3,4,5,6,7,8,9,10,11,12));
- deftuple(t13, (1,2,3,4,5,6,7,8,9,10,11,12,13));
- deftuple(t14, (1,2,3,4,5,6,7,8,9,10,11,12,13,14));
- deftuple(t15, (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15));
- deftuple(t16, (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16));
- assert(tuplen(t0) == 0);
- assert(tuplen(t1) == 1);
- assert(tuplen(t2) == 2);
- assert(tuplen(t3) == 3);
- assert(tuplen(t4) == 4);
- assert(tuplen(t5) == 5);
- assert(tuplen(t6) == 6);
- assert(tuplen(t7) == 7);
- assert(tuplen(t8) == 8);
- assert(tuplen(t9) == 9);
- assert(tuplen(t10) == 10);
- assert(tuplen(t11) == 11);
- assert(tuplen(t12) == 12);
- assert(tuplen(t13) == 13);
- assert(tuplen(t14) == 14);
- assert(tuplen(t15) == 15);
- assert(tuplen(t16) == 16);
- }
- [[noreturn]] int tuple_index_error(size_t length, size_t index) {
- fprintf(stderr, "Attempt to get index %zd of Tuple of length %zd.\n", index, length);
- exit(1);
- }
- int main([[maybe_unused]] int argc,[[maybe_unused]] char** argv) {
- deftuple(tup, (1,"abc",1.7));
- print_tuple(tup);
- printf("\n");
- test();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement