|
Boost Users : |
Subject: Re: [Boost-users] [Iterators] How to implement proxy iterators?
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2012-02-26 16:46:38
On Sun, Feb 26, 2012 at 1:24 PM, Oswin Krause <
Oswin.Krause_at_[hidden]> wrote:
> Hi,
>
> >> Everything works? That would be really nice!
> >>
> >
> > Well, the only way to be sure is to try it :)
> >
> > In this case I am happy and thank you very much for the hint to the
> >> Definition :). This helped me a lot.
> >>
> >
> > Great. Hopefully everything works out. Let us know if it doesn't.
>
> It doesn't :).
>
> Because I was lazy, I just copy pasted the code and added basic
> constructor & op= support to the proxy:
>
> class MatrixRowReference:public MatrixRow{
> public:
> MatrixRowReference( Matrix& matrix, std::size_t i)
> :MatrixRow(matrix,i){}
>
> template<class T>
> const MatrixRowReference& operator=(const T& argument){
> static_cast<MatrixRow&>(*this)=argument;
> return *this;
> }
>
> operator Vector(){
> return Vector(*this);
> }
> };
>
> so, pretty straight forward. The iterator is defined as in the previous
> mail with the base class:
>
> struct ProxyIterator: public boost::iterator_facade<
> ProxyIterator,
> Vector,
> boost::random_access_traversal_tag,
> MatrixRowReference
> >{...};
>
> The error didn't change. And it is now clear to me, that conversion was
> not the Problem in the first place. The quick translated and cleaned error
> message reads:
>
> /usr/include/boost/iterator/iterator_facade.hpp: In static element
> function »static boost::detail::operator_arrow_result<ValueType,
> Reference, Pointer>::type boost::detail::operator_arrow_result<ValueType,
> Reference, Pointer>::make(Reference)
> [with ValueType = Vector, Reference = MatrixRowReference, Pointer =
> Vector*, boost::detail::operator_arrow_result<ValueType, Reference,
> Pointer>::type = boost::detail::operator_arrow_proxy<Vector>]«:
> [snipping backtrace]
> /usr/include/boost/iterator/iterator_facade.hpp:327:49: error: no matching
> function for call to »implicit_cast(MatrixRowReference*)«
> /usr/include/boost/iterator/iterator_facade.hpp:327:49: note: candidates
> are:
> /usr/include/boost/implicit_cast.hpp:18:10: note: template<class T> T
> boost::implicit_cast(typename boost::mpl::identity<T>::type)
>
> looking at the code, it apparently tried to convert MatrixRowReference*
> to operator_arrow_proxy<VectorType>
>
> Checking the definition of this proxy, I'm really not sure how this should
> work. The compiler might try to call the constructor of
> operator_arrow_proxy, but this doesn't seem to be very useful, too:
>
> template <class T>
> struct operator_arrow_proxy
> {
> operator_arrow_proxy(T const* px);
> //snip
> };
>
> im quite sure, that a pointer to my proxy can't be converted to Vector*.
>
> I am still quite certain that the error lies somewhere on my side. So,
> what did I do wrong?
>
Argh, no, that's an error in operator_array_proxy that I haven't gotten
around to fixing; I've recently been added as maintainer of Iterator and
I'm slowing finding time just to get up to speed on the Boost development
practices. The current workaround is to provide your own arrow operator and
your own version of operator_array_proxy that "does the right thing". Or
locally patch Iterator. See
https://svn.boost.org/trac/boost/ticket/5697
- Jeff
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