2

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?

a3f
  • 8,517
  • 1
  • 41
  • 46
Topilski Alexandr
  • 669
  • 1
  • 12
  • 34
  • 1
    What are the arguments to this macro. Can you give example ? Remember that string concatenation can be done by compiler itself and without any use of macro, if they are string literals. – iammilind Jul 20 '12 at 08:04

2 Answers2

2

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)
pmr
  • 58,701
  • 10
  • 113
  • 156
1

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.

Mehrwolf
  • 8,208
  • 2
  • 26
  • 38