Comparing two iterators end ()

list<int> foo;
list<int> foo2;
list<int>::iterator foo_end = foo.end();
list<int>::iterator foo2_end = foo2.end();

for (list<int>::iterator it = foo.begin(); it != foo2_end; ++foo) <- notice != comparison here
{
   ...

It is allowed? will it work correctly.

I am inclined to think that it depends on the implementation, does anyone know what the standard says about this?

+3
source share
3 answers

This was reported by a defect ( LWG defect 446 ). The defect report sets whether to compare iterators related to elements of different containers.

The notes in the defect report explain that it was, of course, the intention to make it undefined, but it was not explicitly stated that it was undefined.

The proposed resolution was to add the following to the standard, explicitly stating that it is undefined:

, r1 r2 ( ), undefined, .

: CCD 0x FCD. N3066; (§24.2.5/2):

== - .

+7

(.. ).
, .

foo2_end foo2, foo, foo , foo2, , foo. , it foo, seg.

. , ++it, ++foo.

+2

, seg. -, . , it != foo2_end true, , it foo.end(), .

+1

Source: https://habr.com/ru/post/1739244/


All Articles