How to make class sortable inside vector?
c++, class, stl, vector
Solution
For sorting, implement an `operator<` that compares two structures:
bool operator<(const stuff& s1, const stuff& s2)
{
// Your comparison here
}
This is the operator that is used by default for most of all sorting.
For equality checking, create an `operator==` similarly.
Problem
I have a class say `class stuff{ int id; int ammount; int quality; /*...*/ };` and I have a `vector<stuff> items`. I want to make my collection sortable by `stuff::id` and searchable by `staff::id`. I could do it via find_if and sort using some sorting special stl lambda based function. Yet I want to have it all by default in vector. I heard there is some way to create hashing function yet I searched all around could not find it... So how to make class sortable/searchable inside vector with default vector functions?