i got that simple problem to be solved:
i want a funktion that is called several times, but the first time it is called it should do something additional.
I know that aint work but you might get a better idea of what i want:
#define DOIT
#ifndef DONEITONCE
#define DONEITONCE
cout << "first time doing it" << endl;
#else
cout << "did it allready" << endl;
#endif
Obviously that won't compile. The question is can i do something similar,
that the code is changed during compile time? I imagined something like this:
bool done = false;
template<bool b="">;
void doit() {
doit<B>();
}
template<>
void doit<false>() {
cout << "first time doing it" << endl;
done = true;
}
template<>;
void doit<true>() {
cout << "did it allready" << endl;
}
#define DOIT doit<done>();</done></true></false></bool>
but that throws a compilation error, too.
Anyway the function call should look like:
DOIT
DOIT
with an output like:
first time doing it
did it allready
I do not want to do this in an <code>if (b) xxx; else yyy;</code> manner
I really hope you can help me!
Tanks