|
Boost Users : |
From: David Abrahams (dave_at_[hidden])
Date: 2005-10-18 07:22:15
"Sigg Christian" <sigg_at_[hidden]> writes:
> Dear boosters,
>
> I'm trying to figure out why there is no way to define the
> iterator_adaptor's pointer type.
Because
a. Generic algorithms never need operator-> in the first place, so
supplying an operator-> usually has little value in itself. It's
just a requirement that must be met to create a legal iterator
b. For any reference type you specify, the library will already
supply a pointer type that's sufficient to meet the standard's
requirements.
c. You can always override the library's choices in your derived class.
> I'm trying to write an iterator that concurrently accesses
> two containers, but the interface should look like it's only
> one container. Therefore, it is necessary to write my own
> value, reference and pointer type.
It's usually not necessary to write your own pointer type.
> However, the iterator_adaptors pointer type is always value*.
That's not true, actually. The library supplies an
operator_arrow_proxy that's used whenever your reference type is not a
true C++ reference.
> Is it save to just overload the pointer typedef and reimplement
> operator->()?
You can certainly do that. Whether it's safe or not may be another
matter.
> I'm not too much of a c++ expert, so if anyone could comment
> on that, I would greatly appreciate it.
Be sure that the category you specify for your iterator is compatible
with the associated types you supply. For example, a forward,
bidirectional, or random access iterator must always have a reference
type of T& or T const&, where T is the value_type.
-- 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