boost::iterator_facade and assignment operation

HI, I'm using the boost iterator_facade class to implement a random access iterator for my class. When I try to assign the iterators to one another, the compiler fails saying 'operator =' function is unavailable". Sample code from my implementation below: |class MyClass{ class Iterator : public boost::iterator_facade<Iterator, T, boost::bidirectional_traversal_tag>{ protected: void increment(); bool equal(const Iterator& rhs)const; //etc || //... Note - no method implemented to support assignment | | } }| I'd assumed that it'll be possible to assign iterators to each other. Why is the assignment operator not supported by iterator_facade. It implements other operations (like ++ and ==)by making the derived version implement private methods (like increment and equal). Am I missing something. The boost documentation doesn't mention why this is not supported. Thanks AR

on Wed Oct 12 2011, Arun Ramasamy <aramasamy-AT-thevisualmd.com> wrote:
HI, I'm using the boost iterator_facade class to implement a random access iterator for my class. When I try to assign the iterators to one another, the compiler fails saying
'operator =' function is unavailable".
Sample code from my implementation below:
class MyClass{ class Iterator : public boost::iterator_facade<Iterator, T, boost::bidirectional_traversal_tag>{ protected: void increment(); bool equal(const Iterator& rhs)const; //etc //... Note - no method implemented to support assignment } }
I'd assumed that it'll be possible to assign iterators to each other. Why is the assignment operator not supported by iterator_facade.
It is. My first guess is that you have added a data member with a private operator=, but there isn't enough information in your post to be sure. I suggest you: a) reduce the problem to a *minimal* example that demonstrates the problem. b) post the example and the *full* error message here. -- Dave Abrahams BoostPro Computing http://www.boostpro.com

Thanks David. Here's some sample test code: #include <vector> #include <boost/iterator/iterator_facade.hpp> class IntVolume{ public: class Iterator : public boost::iterator_facade<Iterator, int, boost::bidirectional_traversal_tag>{ protected: Iterator(IntVolume& v):volume(v),pos(0){} void increment(){pos++;} void decrement(){pos--;} bool equal(const Iterator& rhs)const{return pos == rhs.pos;} int& dereference()const{ return volume.voxels.at(pos);} void advance(ptrdiff_t n){pos+=(int)n;} ptrdiff_t distance_to(const Iterator& rhs)const{return pos-rhs.pos;} friend class IntVolume; friend class boost::iterator_core_access; //private data IntVolume& volume; int pos; }; Iterator begin(){return Iterator(*this);} Iterator end(){ Iterator iter(*this); iter+=100; //assume end is at the 100th element return iter; } private: std::vector<int> voxels; }; void TestIntVolume(){ IntVolume iv; IntVolume::Iterator iter = iv.begin(); iter += 10; iter = iv.begin(); //This fails throwing compiler error, everything else is fine } I just tried this code and this throws error in the line I've indicated. I'm using Boost version 1.44 and vc80 platform toolset in Visual Stdio. Let me know what you think. thanks AR On 10/12/2011 10:38 AM, Dave Abrahams wrote:
on Wed Oct 12 2011, Arun Ramasamy<aramasamy-AT-thevisualmd.com> wrote:
HI, I'm using the boost iterator_facade class to implement a random access iterator for my class. When I try to assign the iterators to one another, the compiler fails saying
'operator =' function is unavailable".
Sample code from my implementation below:
class MyClass{ class Iterator : public boost::iterator_facade<Iterator, T, boost::bidirectional_traversal_tag>{ protected: void increment(); bool equal(const Iterator& rhs)const; //etc //... Note - no method implemented to support assignment } }
I'd assumed that it'll be possible to assign iterators to each other. Why is the assignment operator not supported by iterator_facade. It is. My first guess is that you have added a data member with a private operator=, but there isn't enough information in your post to be sure. I suggest you:
a) reduce the problem to a *minimal* example that demonstrates the problem.
b) post the example and the *full* error message here.
--

Arun Ramasamy wrote:
Thanks David. Here's some sample test code: ... class Iterator : public boost::iterator_facade<Iterator, int, boost::bidirectional_traversal_tag>{ ... IntVolume& volume; int pos;
};
Your Iterator has a reference data member `volume`, so it cannot be copied. If you change a reference to a pointer, everything goes fine. And please don't top-post! ( http://www.boost.org/community/policy.html#quoting ) Regards, Michel

On 10/12/2011 12:17 PM, Michel Morin wrote:
Arun Ramasamy wrote:
Thanks David. Here's some sample test code: ... class Iterator : public boost::iterator_facade<Iterator, int, boost::bidirectional_traversal_tag>{ ... IntVolume& volume; int pos;
}; Your Iterator has a reference data member `volume`, so it cannot be copied. If you change a reference to a pointer, everything goes fine. -- Ok cool. That fixed it. I didn't realize that I was unseating a reference with the assignment. Thanks a lot. And please don't top-post! ( http://www.boost.org/community/policy.html#quoting )
Regards, Michel _____________
__________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
--
participants (3)
-
Arun Ramasamy
-
Dave Abrahams
-
Michel Morin