how do you insert the value in a sorted vector?
ALL, This question is a continuation of this one . I think that STL misses this functionality, but it just my IMHO. Now, to the question. Consider following code: class Foo { public: Foo(); int paramA, paramB; std::string name; }; struct Sorter { bool operator()(const Foo &foo1, const Foo &foo2) const { switch( paramSorter ) { case 1: return foo1.paramA < foo2.paramA; case 2: return foo1.paramB < foo2.paramB; default: return foo1.name < foo2.name; } } int paramSorter; }; int main() { std::vector<Foo> foo; Sorter sorter; sorter.paramSorter = 0; // fill the vector std::sort( foo.begin(), foo.end