Debug-only members

Viewed 492

Is there a nice way of including certain members only in the debug build of a program?

I have an indexed data structure of which I use a large number of instances, which carry certain status flag in case some contents of the data structure have changed, but the index hasn't been updated.
The status flag are only used to check that all uses of the index call the update functionality in case the data has been changed, but for performance and storage reasons, since there are lots of instances and the data structure might be changed a lot before update is called, I would like to keep this data only for the debug build.

There are basically two types of operations on these flags:

  • Setting/Resetting the flag
  • asserting that the flag is not set, i.e. certain parts of the index are still valid.

Are there any nicer ways of achieving this than sprinkling my code with #ifndef NDEBUG statements?

Note: In my special use case, the performance hit might not be that large, but I'm still looking for a general way to approach this, since there are probably much more complex use cases for the same idea.

1 Answers
Related