klopter
asked on
How can I turn on bounds checking in STL vectors?
I would like to be able to turn on bounds checking
for debugging and turn it off on production runs.
What is the easiest way to do this with STL vectors.
Thanks,
Ken
for debugging and turn it off on production runs.
What is the easiest way to do this with STL vectors.
Thanks,
Ken
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Bummer. One of the reasons that I
agreed to switch from arrays to
vectors was to get bounds checking.
There are undoubtably many other good
reasons to convert though.
And, at leastnow I do have some
options for bounds checking.
Ken
agreed to switch from arrays to
vectors was to get bounds checking.
There are undoubtably many other good
reasons to convert though.
And, at leastnow I do have some
options for bounds checking.
Ken
#ifdef DEBUG
GetItem(V,P) V.at(P)
#else
GetItem(V,P) V[P]
#endif
* * *
vector<int> Vec;
int i = GetItem(Vec,5);
I don't really like using the pre-processor to do macros and that short of thing, but that is probalby the only way you can do this. (Well you coudl write your own array class, from scratch or based on vector<>, but that might be more thn you want.)