This is the mail archive of the mailing list for the libstdc++ project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Iterators wrappers?


I am currently working on some test cases for some functions in the algorithm header. I wondered if there exists any "exact iterator checkers", which (for example) given the begin() and end() iterators for a vector would only reveal exactly the required features of a bidirectional iterator and perhaps also further check for things like an iterator being moved after end() or before begin(). Such things would allow for more easily testing if an algorithm is using exactly the properties it is allowed to.

In 3.4.x, to help the programmer with this kind of issues, besides the compile-time concept-checks, we have a new, powerful, run-time debug mode:

To give you a stupid, trivial example, this snippet compiled with -D_GLIBCXX_DEBUG:

#include <vector>
int main()
 std::vector<int> v;
 std::vector<int>::iterator it = v.end();

leads, at run time, to:

   error: attempt to dereference a past-the-end iterator.

Objects involved in the operation:
iterator "this" @ 0x0xbffff690 {
type = N11__gnu_debug14_Safe_iteratorIN9__gnu_cxx17__normal_iteratorIPiN10__gnu_norm6vectorIiSaIiEEEEEN15__gnu_debug_def6vectorIiS6_EEEE (mutable iterator);
state = past-the-end;
references sequence with type `N15__gnu_debug_def6vectorIiSaIiEEE' @ 0x0xbffff690



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]