I've been having some trouble trying to use the STL algorithms on a set of my own struct, I've never had a problem using STL with primitive types ... do I need to overload comparison operators for this to work?
heres some example code which doesnt compile for me!
Code:
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
struct choco_size
{
int r;
int c;
};
bool choco_solve(choco_size size,vector<int>& wanted, map<vector<int>, set<choco_size> >& memo)
{
return memo[wanted].find(size) != memo[wanted].end();
}
int main() {}
error :
Code:
In file included from /usr/include/c++/4.4/bits/stl_tree.h:64,
from /usr/include/c++/4.4/set:60,
from cpf.cpp:3:
/usr/include/c++/4.4/bits/stl_function.h: In member function ‘bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = choco_size]’:
/usr/include/c++/4.4/bits/stl_tree.h:1424: instantiated from ‘std::_Rb_tree_iterator<_Val> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::find(const _Key&) [with _Key = choco_size, _Val = choco_size, _KeyOfValue = std::_Identity<choco_size>, _Compare = std::less<choco_size>, _Alloc = std::allocator<choco_size>]’
/usr/include/c++/4.4/bits/stl_set.h:548: instantiated from ‘typename std::_Rb_tree<_Key, _Key, std::_Identity<_Key>, _Compare, typename _Alloc::rebind<_Key>::other>::const_iterator std::set<_Key, _Compare, _Alloc>::find(const _Key&) [with _Key = choco_size, _Compare = std::less<choco_size>, _Alloc = std::allocator<choco_size>]’
cpf.cpp:16: instantiated from here
/usr/include/c++/4.4/bits/stl_function.h:230: error: no match for ‘operator<’ in ‘__x < __y’
THANKS!!!
any ideas?