diff options
author | John Hodge <tpg@mutabah.net> | 2017-09-02 22:41:54 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2017-09-02 22:41:54 +0800 |
commit | 39dc4793cc8535bb9ad2cc188725398308170b68 (patch) | |
tree | d2d13830db3cfa69dbdaf287ecd18e0b6c6309f7 | |
parent | 433e16af0fc89cf05e5b6f78526a20f24bcbe6d0 (diff) | |
download | mrust-39dc4793cc8535bb9ad2cc188725398308170b68.tar.gz |
TEST - A variant of TU macros to make a switch arm
-rw-r--r-- | src/include/tagged_union.hpp | 3 | ||||
-rw-r--r-- | vsproject/tu_test/main.cpp | 10 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/include/tagged_union.hpp b/src/include/tagged_union.hpp index 6343c623..3afea50b 100644 --- a/src/include/tagged_union.hpp +++ b/src/include/tagged_union.hpp @@ -109,6 +109,9 @@ #define TU_IFLET(CLASS, VAR, TAG, NAME, ...) if(VAR.tag() == CLASS::TAG_##TAG) { auto& NAME = VAR.as_##TAG(); (void)&NAME; __VA_ARGS__ } +// Evil hack: two for loops, the inner stops the outer after it's done. +#define TU_ARM(VAR, TAG, NAME) case ::std::remove_reference<decltype(VAR)>::type::TAG_##TAG: for(bool tu_lc = true; tu_lc;) for(auto& NAME = VAR.as_##TAG(); true; tu_lc=false) + //#define TU_TEST(VAL, ...) (VAL.is_##TAG() && VAL.as_##TAG() TEST) #define TU_TEST1(VAL, TAG1, TEST) (VAL.is_##TAG1() && VAL.as_##TAG1() TEST) #define TU_TEST2(VAL, TAG1, FLD1,TAG2, TEST) (VAL.is_##TAG1() && VAL.as_##TAG1() FLD1.is_##TAG2() && VAL.as_##TAG1() FLD1.as_##TAG2() TEST) diff --git a/vsproject/tu_test/main.cpp b/vsproject/tu_test/main.cpp index 48f7a26c..1ba08393 100644 --- a/vsproject/tu_test/main.cpp +++ b/vsproject/tu_test/main.cpp @@ -43,4 +43,14 @@ int main() (Baz, ) ) + +#if 1 + switch(tmp.tag()) + { + TU_ARM(tmp, Baz, e) { + } break; + TU_ARM(tmp, Bar, e) { + } break; + } +#endif } |