I am trying to define a macros that increases along all source files of my project. Unlike the __COUNTER__ macros which is separate for all files. I tried using a static member variable in a class something like:
class A{ static int GetNextNum() { number++; return number - 1; } private: static int number; }; #define NEXT_NUM A::GetNextNum() But the result is not I want. For instance I want to have the same number for each iteration in this cycle(as would happen with __COUNTER__):
for (int i = 0; i < 10; ++i) { doSomething(NEXT_NUM) } While as I have impemented it it increases on each iteration. Any ideas on how can I achieve what I need? (I am using visual studio but would prefer a compiler independent solution).
EDIT: as requested here is a minimalistic example of something similar to what I want to do. I try to define a class that counts how many times I pass through a given section of the code. Here is how I would use such a class:
for (int i = 0; i < 10; ++i) { ExecuteCounter(location_id); ... do stuff ... } There is also tons of other stuff I keep track of and accumulate in the destructor but I believe this is enough for you to get the idea. At first I used a map where entry is an object where I store the information I care of and string is formed by appending __FILE__ with __LINE__(thus identifies the location uniquely), but this proved to be slow. So instead of using a map I decided to use a table and indices within it. This will removes a logarithm from the overall complexity and improves performance significantly. Hope this explanation makes my question clearer.