Yes, the easiest way is to override the <operator in your class, in which case you do not need to worry about comp.
The comp parameter is a function pointer that wraps two iterators into a vector and returns true or false depending on how you want them to be ordered.
Edit: Unverified, but what it costs:
class myclass { public: myclass() : m_a( 0 ){} void operator = ( int a ) { m_a = a; } private: friend bool operator<( const myclass& lhs, const myclass& rhs ) { return lhs.m_a < rhs.m_a; } int m_a; }; int _tmain(int argc, _TCHAR* argv[]) { myclass c; std::vector<myclass> vec; for( int i = 0; i < 10; ++i ) { c = i; vec.push_back( c ); }
Patrick
source share