How can I place nothings in a list and filter them out? #19
Answered
by
hirrolot
UndarkAido
asked this question in
Q&A
-
I make heavy use of macros in https://github.com/DiscordPP/plugin-endpoints and in merging it with https://github.com/DiscordPP/plugin-objects I decided I needed to macro-ify object definitions. But to make a long story short, what am I doing wrong here and/or is there a better way to do this? #include <metalang99.h>
#if !ML99_VERSION_COMPATIBLE(1, 12, 0)
#error Please, update your Metalang99 to v1.12.0 or higher!
#endif
#define Fields v(field(std::string, name), field(std::string, fact), exclude_field(std::string, hideme), field(std::string, comment), field(std::string, desc))
template<typename t>
class field {
};
void func(
#define field(TYPE, NAME) field<TYPE> NAME = {}
#define exclude_field(TYPE, NAME) ML99_nothing()
#define PRED(s, data, elem) BOOST_PP_NOT(BOOST_PP_EQUAL(elem, nil))
ML99_LIST_EVAL_COMMA_SEP(ML99_listFilter(v(ML99_isNothing), ML99_list(Fields)))
#undef exclude_field
#undef field
){
} CLion claims this evaluates to field<std::string> name = {}, field<std::string>
fact = {},
(0callUneval,ML99_nothing,),
field<std::string> comment = {}, field<std::string>
desc = {} |
Beta Was this translation helpful? Give feedback.
Answered by
hirrolot
Nov 23, 2021
Replies: 1 comment 2 replies
-
This will do the trick: void func(
#define field(TYPE, NAME) ML99_JUST(field<TYPE> NAME = {})
#define exclude_field(TYPE, NAME) ML99_NOTHING()
ML99_LIST_EVAL_COMMA_SEP(ML99_listMap(v(ML99_maybeUnwrap), ML99_listFilter(v(ML99_isJust), ML99_list(Fields))))
#undef exclude_field
#undef field
){
} Expansion:
|
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
UndarkAido
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will do the trick:
Expansion: