Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Macro text manipulation

I would like to write a C++ macro taking arbitrary argument like:

#define MANIP(...) \ 
//Implementation

Such that writing

MANIP(m_a, m_b, m_c);

expands to

f(a, b, c);
g("a", "b", "c");

Is this possible?

Thank you in advance for helping me with this seemingly extravagant question :)

like image 539
StephQ Avatar asked Jan 28 '11 19:01

StephQ


1 Answers

I don't believe there will be an easy way to go from m_a to a. However, the stringize operator # is part of standard C and C++.

for example, given

#define STRING(x) #x

then STRING(m_a) will be transformed to "m_a".

like image 66
Derrick Turk Avatar answered Oct 13 '22 11:10

Derrick Turk