Is there support in C++/STL for sorting objects by attribute?

后端 未结 8 1188
耶瑟儿~
耶瑟儿~ 2020-11-30 05:16

I wonder if there is support in STL for this:

Say I have an class like this :

class Person
{
public:
  int getAge() const;
  double getIncome() const         


        
8条回答
  •  暖寄归人
    2020-11-30 05:44

    You can have just a global function, or a static function. Each of these global or static functions compare against an attribute. No need to make a class. One way to hold papeters for comparison is to use boost bind, but bind is only useful for finding all classes or comparing all classes against some bound parameter. Storing data across multiple elements is the only reason to make a functor.

    Edit: also see boost lambda functions, but they are only practical for simple functions.

提交回复
热议问题