
David Abrahams <dave@boost-consulting.com> writes:
Anthony Williams <anthony_w.geo@yahoo.com> writes:
operator* returns a real reference to an object stored within the iterator. This object is a tuple of references to the objects returned by dereferencing the source iterators, with some custom behaviour to handle copying.
This custom behaviour means that copies of this tuple actually hold copies of the originally-referenced data, and the references on this new copy point back within itself to the copies of the data.
That is evil and sneaky! I love it!
<G>
Is that object the same as the iterator's value_type?
Yes, otherwise it wouldn't be conforming (as you point out below)
If so, I don't see how swap(*i1, *i2) can work, and thus most sort implementations should fail. If not, it's not conforming in another way because operator* must be a reference to value_type. Have I missed something else?
The default implementation of swap is generally along the lines of template<typename T> void swap(T& lhs,T& rhs) { T temp(lhs); lhs=rhs; rhs=temp; } The initialization of temp creates a genuine copy of the data. The two assignments then use the assignment operator of boost::tuple to assign through the references. Does that make it clearer? Anthony -- Anthony Williams Senior Software Engineer, Beran Instruments Ltd.