This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
What does blitz::all() do? Looks like operator<() is defined for TinyVector. In that case you shouldn't need to make your own less since std::less just calls operator<().
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; }
You are dereferencing the end of the map because neither x nor y are contained in dict. AFAIK dereferencing end() is undefined and could do anything. Dig into stl_tree.h to figure out why you might be getting the results you see -- in case you care ;)
Anyway, you need to check whether your key was actually found, somewhere along the lines of
typedef map<blitz::TinyVector<int, 3>, int, blitz::TinyVectorless<int, 3> > dict_type; typedef dict_type::iterator dict_iterator; dict_iterator it = dict.find(x); cout << (it!=dict.end() ? (*it).first : "not found") << endl;
Not tested since I'm not using blitz.
HTH, Peter
PS: You might want to pick up a good book about using the STL like "Effective STL" if you'll be using it more.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |