How to use mutable_queue with non basic types

Hi all, I've used mutable_queue with basic types (double and int) with no problem. Now I trying to do it with my own type: typedef MyObject entry_t; typedef vector<entry_t> storage_t; typedef MySortingCriterion comp_t; typedef boost::identity_property_map prop_map_t; typedef boost::mutable_queue<entry_t, storage_t, comp_t, prop_map_t> queue_t; queue_t Q(100, comp_t(), prop_map_t()); The definition compiles ok but when I perform an operation such Q.push(obj) //MyObject obj The following errors appear: C:\boost\boost_1_42_0/boost/property_map/property_map.hpp: In function 'Reference boost::get(const boost::put_get_helper<Reference, PropertyMap>&, const K&) [with PropertyMap = boost::typed_identity_property_map<unsigned int>, Reference = unsigned int, K = boost::shared_ptr<CAStarNode>]': C:\boost\boost_1_42_0/boost/pending/mutable_queue.hpp:94: instantiated from 'void boost::mutable_queue<IndexedType, RandomAccessContainer, Comp, ID>::push(const IndexedType&) [with IndexedType = boost::shared_ptr<CAStarNode>, RandomAccessContainer = std::vector<boost::shared_ptr<CAStarNode>, std::allocator<boost::shared_ptr<CAStarNode> > >, Comp = astarnode::SGreater, ID = boost::typed_identity_property_map<unsigned int>]' ..\CAStar.cpp:62: instantiated from here C:\boost\boost_1_42_0/boost/property_map/property_map.hpp:318: error: no match for 'operator[]' in '(const boost::typed_identity_property_map<unsigned int>&)((const boost::typed_identity_property_map<unsigned int>*)(& pa))[k]' C:\boost\boost_1_42_0/boost/property_map/property_map.hpp:553: note: candidates are: T boost::typed_identity_property_map<T>::operator[](const T&) const [with T = unsigned int] It seems the problem is with property_map. Anyone knows how to solve it?? Thank you very much, Cheers, Emili

On Fri, 9 Apr 2010, Emili Hernàndez wrote:
Hi all,
I've used mutable_queue with basic types (double and int) with no problem. Now I trying to do it with my own type:
typedef MyObject entry_t; typedef vector<entry_t> storage_t; typedef MySortingCriterion comp_t; typedef boost::identity_property_map prop_map_t; typedef boost::mutable_queue<entry_t, storage_t, comp_t, prop_map_t> queue_t;
identity_property_map is only for unsigned ints (it's that way for historical reasons). Use typed_identity_property_map<entry_t> as prop_map_t and see if that fixes your problem. -- Jeremiah Willcock

Jeremiah Willcock escribió:
On Fri, 9 Apr 2010, Emili Hernàndez wrote:
Hi all,
I've used mutable_queue with basic types (double and int) with no problem. Now I trying to do it with my own type:
typedef MyObject entry_t; typedef vector<entry_t> storage_t; typedef MySortingCriterion comp_t; typedef boost::identity_property_map prop_map_t; typedef boost::mutable_queue<entry_t, storage_t, comp_t, prop_map_t> queue_t;
identity_property_map is only for unsigned ints (it's that way for historical reasons). Use typed_identity_property_map<entry_t> as prop_map_t and see if that fixes your problem.
-- Jeremiah Willcock
Hi, I've tried what you suggested and another error apperars: C:\boost\boost_1_42_0/boost/pending/mutable_queue.hpp: In member function 'void boost::mutable_queue<IndexedType, RandomAccessContainer, Comp, ID>::push(const IndexedType&) [with IndexedType = boost::shared_ptr<CAStarNode>, RandomAccessContainer = std::vector<boost::shared_ptr<CAStarNode>, std::allocator<boost::shared_ptr<CAStarNode> > >, Comp = astarnode::SGreater, ID = boost::typed_identity_property_map<boost::shared_ptr<CAStarNode> >]': ..\CAStar.cpp:76: instantiated from here C:\boost\boost_1_42_0/boost/pending/mutable_queue.hpp:94: error: no match for 'operator[]' in '((boost::mutable_queue<boost::shared_ptr<CAStarNode>, std::vector<boost::shared_ptr<CAStarNode>, std::allocator<boost::shared_ptr<CAStarNode> > >, astarnode::SGreater, boost::typed_identity_property_map<boost::shared_ptr<CAStarNode> >
*)this)->boost::mutable_queue<boost::shared_ptr<CAStarNode>, std::vector<boost::shared_ptr<CAStarNode>, std::allocator<boost::shared_ptr<CAStarNode> > >, astarnode::SGreater, boost::typed_identity_property_map<boost::shared_ptr<CAStarNode> > ::index_array[boost::get(const boost::put_get_helper<Reference, PropertyMap>&, const K&) [with PropertyMap = boost::typed_identity_property_map<boost::shared_ptr<CAStarNode> >, Reference = boost::shared_ptr<CAStarNode>, K = boost::shared_ptr<CAStarNode>](((const boost::shared_ptr<CAStarNode>&)((const boost::shared_ptr<CAStarNode>*)x)))]' c:\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/bits/stl_vector.h:610: note: candidates are: typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::reference std::vector<_Tp, _Alloc>::operator[](size_t) [with _Tp = unsigned int, _Alloc = std::allocator<unsigned int>] c:\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/bits/stl_vector.h:625: note: typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::const_reference std::vector<_Tp, _Alloc>::operator[](size_t) const [with _Tp = unsigned int, _Alloc = std::allocator<unsigned int>] In file included from C:\boost\boost_1_42_0/boost/pending/mutable_queue.hpp:20, from ..\/CAStar.h:90, from ..\CAStar.cpp:8: C:\boost\boost_1_42_0/boost/graph/detail/array_binary_tree.hpp: In member function 'void adstl::array_binary_tree_node<RandomAccessIterator, ID>::swap(adstl::array_binary_tree_node<RandomAccessIterator, ID>, ExternalData&) [with ExternalData = std::vector<unsigned int, std::allocator<unsigned int> >, RandomAccessIterator = __gnu_cxx::__normal_iterator<boost::shared_ptr<CAStarNode>*, std::vector<boost::shared_ptr<CAStarNode>, std::allocator<boost::shared_ptr<CAStarNode> > > >, ID = boost::typed_identity_property_map<boost::shared_ptr<CAStarNode> >]': C:\boost\boost_1_42_0/boost/pending/mutable_heap.hpp:38: instantiated from 'TreeNode boost::up_heap(TreeNode, const Compare&, ExternalData&) [with TreeNode = adstl::array_binary_tree_node<__gnu_cxx::__normal_iterator<boost::shared_ptr<CAStarNode>*, std::vector<boost::shared_ptr<CAStarNode>, std::allocator<boost::shared_ptr<CAStarNode> > > >, boost::typed_identity_property_map<boost::shared_ptr<CAStarNode> > >, Compare = adstl::compare_array_node<std::vector<boost::shared_ptr<CAStarNode>, std::allocator<boost::shared_ptr<CAStarNode> > >, astarnode::SGreater>, ExternalData = std::vector<unsigned int, std::allocator<unsigned int> >]' C:\boost\boost_1_42_0/boost/pending/mutable_queue.hpp:96: instantiated from 'void boost::mutable_queue<IndexedType, RandomAccessContainer, Comp, ID>::push(const IndexedType&) [with IndexedType = boost::shared_ptr<CAStarNode>, RandomAccessContainer = std::vector<boost::shared_ptr<CAStarNode>, std::allocator<boost::shared_ptr<CAStarNode> > >, Comp = astarnode::SGreater, ID = boost::typed_identity_property_map<boost::shared_ptr<CAStarNode> >]' ..\CAStar.cpp:76: instantiated from here C:\boost\boost_1_42_0/boost/graph/detail/array_binary_tree.hpp:143: error: no match for 'operator[]' in 'edata[boost::get(const boost::put_get_helper<Reference, PropertyMap>&, const K&) [with PropertyMap = boost::typed_identity_property_map<boost::shared_ptr<CAStarNode> >, Reference = boost::shared_ptr<CAStarNode>, K = boost::shared_ptr<CAStarNode>](((const boost::shared_ptr<CAStarNode>&)((const boost::shared_ptr<CAStarNode>*)(& tmp))))]' c:\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/bits/stl_vector.h:610: note: candidates are: typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::reference std::vector<_Tp, _Alloc>::operator[](size_t) [with _Tp = unsigned int, _Alloc = std::allocator<unsigned int>] c:\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/bits/stl_vector.h:625: note: typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::const_reference std::vector<_Tp, _Alloc>::operator[](size_t) const [with _Tp = unsigned int, _Alloc = std::allocator<unsigned int>] C:\boost\boost_1_42_0/boost/graph/detail/array_binary_tree.hpp:144: error: no match for 'operator[]' in 'edata[boost::get(const boost::put_get_helper<Reference, PropertyMap>&, const K&) [with PropertyMap = boost::typed_identity_property_map<boost::shared_ptr<CAStarNode> >, Reference = boost::shared_ptr<CAStarNode>, K = boost::shared_ptr<CAStarNode>](((const boost::shared_ptr<CAStarNode>&)((const boost::shared_ptr<CAStarNode>*)adstl::array_binary_tree_node<RandomAccessIterator, ID>::value [with RandomAccessIterator = __gnu_cxx::__normal_iterator<boost::shared_ptr<CAStarNode>*, std::vector<boost::shared_ptr<CAStarNode>, std::allocator<boost::shared_ptr<CAStarNode> > > >, ID = boost::typed_identity_property_map<boost::shared_ptr<CAStarNode> >]())))]' c:\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/bits/stl_vector.h:610: note: candidates are: typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::reference std::vector<_Tp, _Alloc>::operator[](size_t) [with _Tp = unsigned int, _Alloc = std::allocator<unsigned int>] c:\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/bits/stl_vector.h:625: note: typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::const_reference std::vector<_Tp, _Alloc>::operator[](size_t) const [with _Tp = unsigned int, _Alloc = std::allocator<unsigned int>]
it seams that the operator[] has to be defined but I don't understand why is it required if it is already specified to use a vector<entry_t> as storage type Any suggestion? Is there a full example on how to use mutable_queue with non-basic types?? Thanks Emili
------------------------------------------------------------------------
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

On Mon, 12 Apr 2010, Emili Hernàndez wrote:
Jeremiah Willcock escribió:
On Fri, 9 Apr 2010, Emili Hernàndez wrote:
Hi all,
I've used mutable_queue with basic types (double and int) with no problem. Now I trying to do it with my own type:
typedef MyObject entry_t; typedef vector<entry_t> storage_t; typedef MySortingCriterion comp_t; typedef boost::identity_property_map prop_map_t; typedef boost::mutable_queue<entry_t, storage_t, comp_t, prop_map_t> queue_t;
identity_property_map is only for unsigned ints (it's that way for historical reasons). Use typed_identity_property_map<entry_t> as prop_map_t and see if that fixes your problem.
-- Jeremiah Willcock
Hi, I've tried what you suggested and another error apperars:
Could you please post the relevant part of the new code? It appears that the storage indexing is messed up in the property map, and it could be that you need a different index map (if you're using boost::shared_ptr<CAStarNode> as the index type in the property map).
it seams that the operator[] has to be defined but I don't understand why is it required if it is already specified to use a vector<entry_t> as storage type
Any suggestion? Is there a full example on how to use mutable_queue with non-basic types??
I doubt it -- mutable_queue is mostly used internally. If we end up working one out together I can put it in, though. -- Jeremiah Willcock

Jeremiah Willcock escribió:
On Mon, 12 Apr 2010, Emili Hernàndez wrote:
Jeremiah Willcock escribió:
On Fri, 9 Apr 2010, Emili Hernàndez wrote:
Hi all,
I've used mutable_queue with basic types (double and int) with no problem. Now I trying to do it with my own type:
typedef MyObject entry_t; typedef vector<entry_t> storage_t; typedef MySortingCriterion comp_t; typedef boost::identity_property_map prop_map_t; typedef boost::mutable_queue<entry_t, storage_t, comp_t, prop_map_t> queue_t;
identity_property_map is only for unsigned ints (it's that way for historical reasons). Use typed_identity_property_map<entry_t> as prop_map_t and see if that fixes your problem.
-- Jeremiah Willcock
Hi, I've tried what you suggested and another error apperars:
Could you please post the relevant part of the new code? It appears that the storage indexing is messed up in the property map, and it could be that you need a different index map (if you're using boost::shared_ptr<CAStarNode> as the index type in the property map).
it seams that the operator[] has to be defined but I don't understand why is it required if it is already specified to use a vector<entry_t> as storage type
Any suggestion? Is there a full example on how to use mutable_queue with non-basic types??
I doubt it -- mutable_queue is mostly used internally. If we end up working one out together I can put it in, though.
-- Jeremiah Willcock
Here's the code for the class I want to used the mutable_queue: class CAStarNode; #include <boost/shared_ptr.hpp> typedef boost::shared_ptr<CAStarNode> CAStarNodePtr; class CAStarNode { public: CAStarNode(const CVector2& point, const long int& g, const long int& h):point_(point),g_(g),h_(h),f_(g + h) {parent_.reset();}; CAStarNode(const CVector2& point, const long int& g, const long int& h, CAStarNodePtr parent) :point_(point),g_(g),h_(h),f_(g + h), parent_(parent){}; CAStarNode(const CAStarNode& n):point_(n.point_),g_(n.g_),h_(n.h_),f_(n.g_ + n.h_),parent_(n.parent_){}; void operator=(const CAStarNode& n) { // copy suff } bool operator<(const CAStarNode& n) const {return (f_ < n.f_);} bool operator>(const CAStarNode& n) const {return (f_ > n.f_);} CVector2 getPoint() const {return point_;}; long int getF() const {return f_;}; long int getH() const {return h_;}; long int getG() const {return g_;}; void setG(const long int g) { g_ = g; f_ = g_ + h_; }; CAStarNodePtr getParent() const {return parent_;}; void setParent(CAStarNodePtr parent) {parent_ = parent;}; private: CVector2 point_; long int g_, h_, f_; CAStarNodePtr parent_; // Backpointer }; // a criterion to sort a priority_queue /mutable_queue namespace astarnode { struct SGreater : std::binary_function<CAStarNodePtr&, CAStarNodePtr&, bool> { bool operator()(const CAStarNodePtr& n1, const CAStarNodePtr& n2) const { return (*n1 > *n2); } }; } typedef CAStarNodePtr entry_t; typedef vector<entry_t> storage_t; typedef astarnode::SGreater comp_t; typedef boost::typed_identity_property_map<entry_t> prop_map_t; typedef boost::mutable_queue<entry_t, storage_t, comp_t, prop_map_t> queue_t; Then in the cpp file: queue_t open(100, comp_t(), prop_map_t()); CAStarNodePtr currNode; currNode.reset(new CAStarNode(start_, 0, value)); open.push(currNode); Basically, I use the mutable_queue to keep sorted a vector of pointers of CAStarNode's. The project only fails to build when using the mutable_queue methods, not the definition itself. Thank you, Emili
------------------------------------------------------------------------
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (2)
-
Emili Hernàndez
-
Jeremiah Willcock