diff --git a/include/boost/contract/ext_/preprocessor/keyword/utility/is.hpp b/include/boost/contract/ext_/preprocessor/keyword/utility/is.hpp index 3b267eb..286f85c 100644 --- a/include/boost/contract/ext_/preprocessor/keyword/utility/is.hpp +++ b/include/boost/contract/ext_/preprocessor/keyword/utility/is.hpp @@ -22,7 +22,8 @@ // Precondition: A macro named `cat_to_comma_prefix ## token-to-check` must be // #defined to expand to `,`. // Precondition: tokens must start with a token concatenable to a macro name -// (e.g., a literal or integral token) or with parenthesis. +// (e.g., a literal or integral token) or with parenthesis (i.e., +// leading parenthesis are allowed). #define BOOST_CONTRACT_EXT_PP_KEYWORD_UTILITY_IS_FRONT( \ cat_to_comma_prefix, tokens) \ BOOST_PP_IIF(BOOST_CONTRACT_EXT_PP_HAS_PAREN(tokens), \ @@ -34,14 +35,12 @@ // Precondition: A macro named `token-to-check ## cat_to_comma_postfix` must be // #defined to expand to `,`. // Precondition: tokens must end with a token concatenable to a macro name -// (e.g., a literal or integral token) or with parenthesis. +// (e.g., a literal or integral token) and trailing parenthesis +// are NOT allowed. #define BOOST_CONTRACT_EXT_PP_KEYWORD_UTILITY_IS_BACK( \ cat_to_comma_postfix, tokens) \ - BOOST_PP_IIF(BOOST_CONTRACT_EXT_PP_HAS_PAREN(tokens), \ - 0 BOOST_PP_TUPLE_EAT(2) \ - , \ - BOOST_CONTRACT_EXT_PP_KEYWORD_UTILITY_IS_CHECK_ \ - )(tokens, cat_to_comma_postfix) + BOOST_CONTRACT_EXT_PP_KEYWORD_UTILITY_IS_CHECK_( \ + tokens, cat_to_comma_postfix) #endif // #include guard diff --git a/include/boost/contract/ext_/preprocessor/utility/expand.hpp b/include/boost/contract/ext_/preprocessor/utility/expand.hpp index 6652f4f..9587adb 100644 --- a/include/boost/contract/ext_/preprocessor/utility/expand.hpp +++ b/include/boost/contract/ext_/preprocessor/utility/expand.hpp @@ -4,6 +4,11 @@ /* PUBLIC */ +// TODO: Is this /really/ needed? After all pp-traits are impl, try to remove +// this and see if it's really needed. +// TODO: Same thing for *any* use of BOOST_PP_EXPAND: make sure these are all +// absolutely necessary! + // Expand its argument once // NOTE: `BOOST_PP_EXPAND` expands it twice instead: // EXPAND_ONCE(x) --> x (x expanded once) diff --git a/include/boost/contract/ext_/preprocessor/variadic/enum_to_seq.hpp b/include/boost/contract/ext_/preprocessor/variadic/enum_to_seq.hpp new file mode 100644 index 0000000..a59ddd0 --- /dev/null +++ b/include/boost/contract/ext_/preprocessor/variadic/enum_to_seq.hpp @@ -0,0 +1,47 @@ + +#ifndef BOOST_CONTRACT_EXT_PP_VARIADIC_ENUM_TO_SEQ_HPP_ +#define BOOST_CONTRACT_EXT_PP_VARIADIC_ENUM_TO_SEQ_HPP_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* PRIVATE */ + +// Wrapped with parenthesis after removal of NIL so to make it a pp-seq elem. +#define BOOST_CONTRACT_EXT_PP_VARIADIC_ENUM_TO_SEQ_REMOVE_NIL_(back) \ + (BOOST_CONTRACT_EXT_PP_NIL_REMOVE_BACK(back)) + +#define BOOST_CONTRACT_EXT_PP_VARIADIC_ENUM_TO_SEQ_BACK_(seq, back) \ + BOOST_PP_SEQ_POP_BACK(seq) \ + BOOST_PP_IIF(BOOST_CONTRACT_EXT_PP_IS_NIL_FRONT(back), \ + BOOST_PP_TUPLE_EAT(1) \ + , \ + BOOST_CONTRACT_EXT_PP_VARIADIC_ENUM_TO_SEQ_REMOVE_NIL_ \ + )(back) + +#define BOOST_CONTRACT_EXT_PP_VARIADIC_ENUM_TO_SEQ_(seq) \ + BOOST_CONTRACT_EXT_PP_VARIADIC_ENUM_TO_SEQ_BACK_(seq, \ + BOOST_PP_SEQ_ELEM(BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(seq)), seq)) + +/* PUBLIC */ + +// Expand EMPTY() to EMPTY(), otherwise variadic to seq allowing for an +// optional trailing comma (like with C++ enumerations): +// `` to `` +// `x, ..., y` to (x)...(y) +// `x, ..., y,` to (x)...(y) (handle optional trailing comma `,`) +// Implementation: Tokens must be front-concatenable and cannot be specified as +// NIL (because they are internally for being NIL). +#define BOOST_CONTRACT_EXT_PP_VARIADIC_ENUM_TO_SEQ(...) \ + BOOST_CONTRACT_EXT_PP_VARIADIC_ENUM_TO_SEQ_( \ + BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__ BOOST_PP_NIL)) + +#endif // #include guard + diff --git a/include/boost/contract/ext_/preprocessor/variadic/to_seq.hpp b/include/boost/contract/ext_/preprocessor/variadic/to_seq.hpp new file mode 100644 index 0000000..e30a5ab --- /dev/null +++ b/include/boost/contract/ext_/preprocessor/variadic/to_seq.hpp @@ -0,0 +1,20 @@ + +#ifndef BOOST_CONTRACT_EXT_PP_VARIADIC_TO_SEQ_HPP_ +#define BOOST_CONTRACT_EXT_PP_VARIADIC_TO_SEQ_HPP_ + +#include +#include +#include + +/* PUBLIC */ + +// Expand EMPTY() to EMPTY(), otherwise expand variadic data to pp-seq. +#define BOOST_CONTRACT_EXT_PP_VARIADIC_TO_SEQ(...) \ + BOOST_PP_IIF(BOOST_CONTRACT_EXT_PP_IS_EMPTY(__VA_ARGS__), \ + BOOST_PP_EMPTY \ + , \ + BOOST_PP_VARIADIC_TO_SEQ \ + )(__VA_ARGS__) + +#endif // #include guard +