dimanche 28 juin 2015

C++ preprocessor--join arguments

Is there a way to make the C++ preprocessor join arguments with a joiner token?

I've learned that I can do:

#include <boost/preprocessor/seq/cat.hpp>
#define arg1 foo
#define arg2 bar
#define arg3 baz
BOOST_PP_SEQ_CAT((arg1)(_)(arg2)(_)(arg3))

to get foo_bar_baz.

I have two questions:

  1. Is there a way to do it for without the repeated explicit joiner characters ((_)) and for an argument list of variadic length?
  2. Is it necessary to pass the arguments like so:

    (arg1)(arg2)(arg3)
    
    

    Can I wrap it in another macro that'll allow me to pass argument normally, i.e.?:

    arg1, arg2, arg3
    
    

Aucun commentaire:

Enregistrer un commentaire