M
mk
I will have 2 build types of my program: debug and release. In debug
build I want std::vector indexing operation (operator[] or at()) to do
a range-check. In release build I don't want it.
What is the easiest way to achieve that?
I currently have couple solutions, each one with drawbacks:
1. each time I change a build, search-and-replace in whole code
vector:perator[] with at() or vice-versa (this is not really a
solution of course)
2. derive a class from std::vector and override operator[] to do what
I need based on DEBUG macro.
This has a drawback of using non-standard class name (e.g. Vector)
that can potentially confuse future maintainers of the program.
Additionally, operator[] is not virtual, so overriding it is not
entirely safe, as the old one can be invoked accidentally under some
circumstances.
cheers,
Marcin Kalicinski
build I want std::vector indexing operation (operator[] or at()) to do
a range-check. In release build I don't want it.
What is the easiest way to achieve that?
I currently have couple solutions, each one with drawbacks:
1. each time I change a build, search-and-replace in whole code
vector:perator[] with at() or vice-versa (this is not really a
solution of course)
2. derive a class from std::vector and override operator[] to do what
I need based on DEBUG macro.
This has a drawback of using non-standard class name (e.g. Vector)
that can potentially confuse future maintainers of the program.
Additionally, operator[] is not virtual, so overriding it is not
entirely safe, as the old one can be invoked accidentally under some
circumstances.
cheers,
Marcin Kalicinski