Questions tagged [preprocessor-meta-program]

Meta-programming is writing programs that generate programs. This tag is used when language preprocessor is used to write more programs. Meta-programming using a prepreprocessor such a the C preprocessor using in the C or C++ compilers.

Meta-programming is writing programs that generate programs. This tag is used when language preprocessor is used to write more programs. Meta-programming using a pre-preprocessor such a the C preprocessor using in the C or C++ compilers.

There are several reference papers and documents that are useful in understanding pre-processor meta-programming:

10 questions
6
votes
2 answers

Is C++ preprocessor metaprogramming Turing-complete?

I know C++ template metaprogramming is Turing-complete. Does the same thing hold for preprocessor metaprogramming?
4
votes
1 answer

How to parse tokens separated by whitespace in C++ preprocessor?

I'm doing some preprocessor meta-programming and I need a way to convert f(a b) to g(a,b) in C++ preprocessor. Since a and b are two tokens in C++, it seems possible to find a way to separate them. However, after hours of work there is still no…
lz96
  • 2,816
  • 2
  • 28
  • 46
3
votes
2 answers

I'd like a preprocessing language for metaprogramming

I'm looking for a language sort of like PHP, but more brief -- I'm tempted to call it a "templating engine" but I'm pretty sure that's the wrong term. What is the right term? A text preprocessor? Anyway I'd like it to be .NET-based because I want to…
Qwertie
  • 16,354
  • 20
  • 105
  • 148
3
votes
2 answers

How to get c++ function caller name at preprocessing stage

I have to use a macro PERF_INSTRUMENT from a library. PERF_INSTRUMENT expects a user provided c-style string as a function name to print the location of this instrument point. But, I don't want to write the function name everytime I use…
2
votes
3 answers

C++ generic programming subtleties

The problem I have is illustrated in the following code. #include #define X 4 int main() { std::cout << "should be 4: " << X << std::endl; #define Y X + 4 std::cout << "should be 8: " << Y << std::endl; #undef Y #define Y…
Hassan Syed
  • 20,075
  • 11
  • 87
  • 171
2
votes
2 answers

Expand Variadic Template in Vardiadic Macro (how to extract arguments names from a target function)

I am struggling with challenging, but yet simple problem. Let say that I have a target function as follow void target_fnc(int arg1, double arg2) { /* do something here */ } and what I would like to "extract" is the variable names (i.e. 'arg1',…
1
vote
1 answer

C preprocessor metaprogramming: replace macro not in argument list

This question concerns "C preprocessor metaprogramming", i.e. stuff such as this, this, this, this, etc. I'm writing a non-trivial C preprocessor metaprogram, which in particular needs to "call" macros recursively (using the standard DEFER/EVAL…
swineone
  • 2,296
  • 1
  • 18
  • 32
0
votes
1 answer

Macro expansion problems in MSVC

I wonder why this macro is expanding so much. #define CONCAT_IMPL(A, B) A##B #define CONCAT(A, B) CONCAT_IMPL(A, B) #define EAT(...) #define TEST(ARG) EXPANDED, ARG) EAT( #define GET_LAST(A, B) B int result = 0; result = GET_LAST(CONCAT(TEST,…
0
votes
0 answers

Evaluate non-type template argument in conditional macro

I want to implement the for each idiom for traversing all pixels/voxels of a 2d/3d matrix. Depending on the dimension, we have 2 loops or 3 loops. The code seems like that: //template class for point template struct Point{ int…
Vincent
  • 63
  • 6
0
votes
1 answer

File iteration with the preprocessor

Am I correct that boost's file recursion requires that the file using the recursion must be in the include path? I don't see it anywhere in the documentation, but I just debugged a problem where this seems to be the case. This makes using this as a…
Adrian
  • 10,246
  • 4
  • 44
  • 110