jeudi 1 août 2019

How can we construct a set element using the set constructor example below?

I have been studying the set container of c++ and I got confused by an example code that is provided at http://www.cplusplus.com/reference/set/set/set/ as an example to utilize set constructors.

I understand that set has an input parameter called comp to determine how the ordering is done, however when I checked the declarations for the constructors of set at http://www.cplusplus.com/reference/set/set/set/, I couldn't see a declaration that accepts two arguments as template parameters in the way we create a set element below. Would someone be kind enough to explain to me what type of set constructor is called here and how this specific constructor works?

...

struct classcomp {
  bool operator() (const int& lhs, const int& rhs) const
  {return lhs<rhs;}
};

int main ()
{
  ...

  std::set<int,classcomp> fifth;                 // class as Compare

  ...
}

Aucun commentaire:

Enregistrer un commentaire