I'm interested in being able to do something like this:
void ISR()
{
MEASURE_TIME(counters)
do_something();
MEASURE_TIME(counters)
do_something_else();
MEASURE_TIME(counters)
do_another_thing();
MEASURE_TIME(counters)
do_one_last_thing();
MEASURE_TIME(counters)
}
which would somehow translate at compile time to this:
void ISR()
{
counters[0] = measure_time();
do_something();
counters[1] = measure_time();
do_something_else();
counters[2] = measure_time();
do_another_thing();
counters[3] = measure_time();
do_one_last_thing();
counters[4] = measure_time();
}
Is there a way to do maintain and increment integer state with the preprocessor (seems unlikely) or templates?
I know I can do this:
void ISR()
{
int i = 0;
counters[i++] = measure_time();
do_something();
counters[i++] = measure_time();
do_something_else();
counters[i++] = measure_time();
do_another_thing();
counters[i++] = measure_time();
do_one_last_thing();
counters[i++] = measure_time();
}
but there's some additional value to having a compile-time index (which is difficult to explain here w/o getting into some proprietary details)
edit: this is on an embedded system, and __COUNTER__
isn't available (I just tried it: __COUNTER__
is not defined by my compiler or the preprocessor), and I'm not sure I could get Boost to work, at least not in its entirety.