Question

I got stuck here...

#define CONCAT(a,b) BOOST_PP_STRINGIZE(BOOST_PP_CAT(a,b))
#define CONCAT1(a,b,c) CONCAT(CONCAT(a,b),c) and so on.

How i can to generate the CONCAT macro even if 20 arguments? May be i can to use BOOST_PP_SEQ_FOR_EACH but i don't understand how to do it?

Was it helpful?

Solution

It depends on you use-case.

This

#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/stringize.hpp>
#include <boost/preprocessor/seq/for_each.hpp>

#define SEQ (a)(b)(c)

BOOST_PP_STRINGIZE(BOOST_PP_SEQ_CAT(SEQ)) // "abc"

will concatenate the sequence and then stringize it. It is also possible to simply stringize each argument as "a" "b" "c" is equivalent to "abc".

#define MY_STRINGIZE(r, data, elem) BOOST_PP_STRINGIZE(elem)
BOOST_PP_SEQ_FOR_EACH(MY_STRINGIZE, _, SEQ)

OTHER TIPS

As you are already using the Boost libraries, try BOOST_PP_SEQ_CAT (documentation). It takes a list of elements and simply concatenates them together, i.e. BOOST_PP_SEQ_CAT(a b c) results in abc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top