|
Boost Users : |
From: David Abrahams (dave_at_[hidden])
Date: 2006-04-07 09:07:00
Sebastian Weber <sebastian.weber_at_[hidden]> writes:
> Hi!
>
>> It shouldn't. Implicit conversions are generally dangerous; there's
>> no good reason to allow one here.
>
> Well, that might be in general the case. But at least in my case I think
> it does make sense: random_set_iterator is basically a
> std::vector<>::iterator with the noteable difference that the
> next-operation ++ is replaced by a function which moves the iterator to
> a random element in within the vector. And as I do want to delete
> elements from the vector which I find by the random-iterator, I need the
> conversion.
Surely you don't *need* it. v.erase(x.base()) will work just fine.
>> > I'm sure, it should not hard to
>> > implement somthing like this, but how?
>>
>> You can easily add an
>>
>> operator base_iterator_type() const
>>
>> to random_set_iterator, but we (the authors of iterator_adaptor) don't
>> recommend it.
>
> Thanks, that did it.
You're welcome. But just remember, we warned you. Don't be surprised
if you find that you are seeing unexpected effects due to the implicit
conversion. For example, your iterators random_set_iterator is
probably not random access, but I bet you can now write i1 < i2.
Stranger effects where code compiles but does something you didn't
intend are possible.
Good Luck,
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net