0

Is it possible to prefix each element of variadic parameters with something else?

#define INPUTS(...)  ???

Function(INPUTS(a, b, c))

should become

Function(IN a, IN b, IN c)
M.kazem Akhgary
  • 18,645
  • 8
  • 57
  • 118
  • No "universal" way because function-like macro do not support true recursion and overloading. SO there must be hacks limiting number of possible arguments to the number of intermediate macro definitions: https://stackoverflow.com/questions/27765387/distributing-an-argument-in-a-variadic-macro – Swift - Friday Pie Jan 18 '23 at 02:55
  • My advise don't use macros, keep code as close to standard C++ as you can (it will keep code readable for everyone else). It looks like you want complex macros to safe a bit of typing, not to make code more readable. If you are interested in C++ having IN/OUT parameters watch this : [Empirically Measuring, & Reducing, C++’s Accidental Complexity - Herb Sutter - CppCon 2020](https://www.youtube.com/watch?v=6lurOCdaj0Y). Where herb explains about how he would like C++ to have this feature out of the box. – Pepijn Kramer Jan 18 '23 at 04:23

1 Answers1

0

Take a look at Boost.Preprocessor.

While daunting, it can be used to do all kinds of weird things, like exactly this:

#include <boost/preprocessor.hpp>

#define MAKE_IN_ARG(r,_,arg) (IN arg)
#define ARGS(...) \
  BOOST_PP_SEQ_TO_TUPLE( \
    BOOST_PP_SEQ_FOR_EACH(MAKE_IN_ARG,, \
      BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)))
      
void f ARGS( int a, float b, char c )
{
  //...
}

Produces:

void f (IN int a, IN float b, IN char c )
{

}

That said...

You are making a mistake. Don’t do this. Just type out the IN in front of every input argument when you write the function header. Your life will be significantly easier.

Dúthomhas
  • 8,200
  • 2
  • 17
  • 39