Topic: Are iterators from different containers comparable?


Author: =?ISO-8859-1?Q?Joaqu=EDn_M_L=F3pez_Mu=F1oz?= <joaquin@tid.es>
Date: Wed, 17 Dec 2008 16:13:44 CST
Raw View
I've looked up in the standard and equality comparison between
iterators
associated to different containers seems not to be banned, i.e. looks
like
the following is legal C++:

 #include <set>

 int main()
 {
   std::set<int> s1,s2;
   std::set<int>::iterator it1=s1.begin(),it2=s2.begin();
   it1==it2;
 }

However, "safe mode" frameworks like for instance that of Visual
Studio
assert on the program above, and in general I think there's a general
opinion that you can only compare iterators from the same container.

Anyone can point to the relevant sections of the standard, if any,
clarifying this issue?

Thank you,

Joaqu   n M L   pez Mu   oz
Telef   nica, Investigaci   n y Desarrollo


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: sdt <sjdutoit@gmail.com>
Date: Wed, 17 Dec 2008 17:27:09 CST
Raw View
On Dec 17, 5:13 pm, Joaqu   n M L   pez Mu   oz <joaq...@tid.es> wrote:
> I've looked up in the standard and equality comparison between
> iterators
> associated to different containers seems not to be banned, i.e. looks
> like
> the following is legal C++:
>
>  #include <set>
>
>  int main()
>  {
>    std::set<int> s1,s2;
>    std::set<int>::iterator it1=s1.begin(),it2=s2.begin();
>    it1==it2;
>  }
>
> However, "safe mode" frameworks like for instance that of Visual
> Studio
> assert on the program above, and in general I think there's a general
> opinion that you can only compare iterators from the same container.
>
> Anyone can point to the relevant sections of the standard, if any,
> clarifying this issue?

There is an active issue (#446) for this, see:
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#446

Stefanus


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]