Re: Implicit conversion of iterator to reverse_iterator
On 30 Apr., 16:03, dasjotre <dasjo...@googlemail.com> wrote:
On 30 Apr, 10:27, bb <muralibal...@gmail.com> wrote:
Hi,
Please could you clarify why 'implicit conversion' does not take place
while assigning an iterator to reverse_iterator. However, it happens
while initializing/constructing.
e.g.
typedef std::map<int, std::string> MIS;
MIS m1;
// populating m1
MIS::iterator it = m1.lower_bound(4);
// checking the validity of 'it' etc.
MIS::reverse_iterator rit1(it); // implicit conversion takes place
as expected
this is explicit constructor call.
if implicit conversion was allowed
what would you expect compiler to
do with:
for_each(m1.begin(), m1.end(), do_something());
// followed by
for_each(m1.rbegin(), m1.rend(), do_something());
how woudl you expect for_each to make distinction
between reverse_iterator and iterator?
I do not see the problem here. An iterator is not a reverse iterator,
and both functions would be "perfect fits". What could be dangerous
would be to mix iterators and reverse_iterators, but in templated code
where no implicit conversions are made, I see no problems.
/Peter