problems using blitz::TinyVector as key for map

Faheem Mitha faheem@email.unc.edu
Fri Oct 7 06:18:00 GMT 2005


Hi,

I'm having problems with using 'find' on a map whose key is a 
blitz::TinyVector<T, N>. See http://www.oonumerics.org/blitz/ for more 
information about the Blitz++ library.

Can anyone tell me if I'm doing something wrong, or is this a bug?

Thanks.                                                    Faheem.

******************************************************************
g++ -o foo foo.cc

$ ./foo
3 [         50        50        49 ]
3 [          0         0         0 ]

******************************************************************
foo.cc
******************************************************************
#include <iostream>
#include <map>
#include <blitz/array.h>
#include <blitz/tinyvec-et.h>

using std::map;
using std::cout;
using std::endl;

namespace blitz
{
   // Less operator (function object) for TinyVector.
   template<typename T, int N>
   class TinyVectorless
   {
   public:
     inline bool operator() (const blitz::TinyVector<T, N>& u, const 
blitz::TinyVector<T, N>& v) const
     {
       return blitz::all(u < v);
     }
   };
}

int main()
{
   map<blitz::TinyVector<int, 3>, int, blitz::TinyVectorless<int, 3> > 
dict;
   dict[blitz::TinyVector<int, 3>(50, 50, 49)] = 0;
   dict[blitz::TinyVector<int, 3>(60, 60, 60)] = 1;
   blitz::TinyVector<int, 3> x(2, 2, 1000);
   blitz::TinyVector<int, 3> y(2, 2, 2);
   cout << (dict.find(x))->first << endl;
   cout << (dict.find(y))->first << endl;
   return 0;
}



More information about the Libstdc++ mailing list