|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
ublas::vector in std::mapHi,
I tried using a ublas vector as key type in a std::map along the lines of boost::ublas::vector<double> x(2); std::map<boost::ublas::vector<double>, int> vm; vm[x] = 1; which wont compile (gcc 4.0.3) due to /usr/lib/gcc/x86_64-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/stl_function.h:227: error: no match for ‘operator<’ in ‘__x < __y’. Adding an implementation of bool operator<(boost::ublas::vector<double> const& A, boost::ublas::vector<double> const& B) {...} unfortunately doesnt help. Could anyone please point out what I am missing? |
|
|
Re: ublas::vector in std::mapI have the same issue (though I am using ublas::bounded_vector instead). This would be a great feature to have. Is anyone looking into this or have a solution? (I'm using gcc v4.1.2, boost svn trunk at 2008-05-12 around v1.35) martux wrote: > > Hi, > I tried using a ublas vector as key type in a std::map along the lines of > > boost::ublas::vector<double> x(2); > std::map<boost::ublas::vector<double>, int> vm; > vm[x] = 1; > > which wont compile (gcc 4.0.3) due to > > /usr/lib/gcc/x86_64-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/stl_function.h:227: > error: no match > for ‘operator<’ in ‘__x < __y’. > > Adding an implementation of > > bool operator<(boost::ublas::vector<double> const& A, > boost::ublas::vector<double> const& B) {...} > > unfortunately doesnt help. Could anyone please point out what I am > missing? > -- View this message in context: http://www.nabble.com/ublas%3A%3Avector-in-std%3A%3Amap-tp9338948p17566266.html Sent from the Boost - uBLAS mailing list archive at Nabble.com. _______________________________________________ ublas mailing list ublas@... http://lists.boost.org/mailman/listinfo.cgi/ublas |
|
|
Re: ublas::vector in std::map followupI am working on a fieldmap object based on std::map of ublas::bounded_vectors so that I can take advantage of matrix multiplication of ublas as well as the storage/iterators of std::map. However, ublas::vector (and ublas::bounded_vector) do not have the necessary properties to comply with the requirements of the Key value of a std::map. I have a workaround, though I am sure it could be written in a much more general way, I just don't know how to do it. Since I am working with bounded_vector<int, dimension> where dimensions are small, I created a operator< and a functor bouded_vector_less<T> and pass this to the third template parameter of std::map. Thus: template<typename _Tp, size_t _Dim> inline bool operator<( const bounded_vector<_Tp, _Dim>& __x, const bounded_vector<_Tp, _Dim>& __y ) { return std::lexicographical_compare( __x.begin(), __x.end(), __y.begin(), __y.end() ); } template <typename _Tp> struct my_less { bool operator()( const _Tp& __x, const _Tp& __y ) const { return __x < __y; } }; This is more or less a copy of what is in the standard template library. Therefore, when I create the map I can do this: std::map< ublas::bounded_vector<int, 3>, ublas::bounded_vector<float, 3>, my_less< ublas::bounded_vector<int, 3> > > fieldmap; Any suggestions on making this more general and/or more efficient would be greatly appreciated! |
| Free embeddable forum powered by Nabble | Forum Help |