Boost logo

Boost Users :

Subject: [Boost-users] Assignment of ptr_container<A>::iterator value to ptr_container<B>::iterator variable
From: Rob Desbois (rob.desbois_at_[hidden])
Date: 2011-09-28 11:39:04

So I've got a few ptr_container instances floating around, and have
just tracked down a bug caused by (my) naff code essentially akin to
the following:
   ptr_vector<int> vi;
   ptr_vector<string> vs;
   bool eq = (vi.begin() == vs.begin());

After digging I discovered the operator in question in void_ptr_iterator.hpp:
  template< class VoidIterT, class T, class VoidIterU, class U >
  inline bool operator==( const void_ptr_iterator<VoidIterT,T>& l,
                          const void_ptr_iterator<VoidIterU,U>& r )

What is the reason for implementing comparison between different
iterator types? I have a few guesses but unsure of whether they're
sensible ones or not!

Of course disallowing comparison between differing pointer types won't
save people from comparing iterators from different containers, but I
think it's a little too easy to fall into this trap, and difficult to
spot the error once written in. (The equality comparison was an
unlikely case, and fortunately found it during thorough unit testing
:-) )

Is there any sensible way to suppress this behaviour, or are there any
comments on why I might be being a muppet?


Rob Desbois
Eml: rob.desbois_at_[hidden]

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at