I have a container class called people that stores a set of person objects. People takes in an std::function as one of set parameters. this is used to define a custom comparator to sort the set.
is it possible to covert from
set<Person, std::function<bool(const Person &p1, const Person &p2)>>
to
set<Person>
A simplified version of the class is below
class People
{
public :
People() : people(compareByName()) {}
void addPerson(Person p);
set<Person> getPeople();
private:
using PeopleSet = set<Person, std::function<bool(const Person &p1, const Person &p2)>>; // std::function for comparator type
PeopleSet people;
};
set<Person> People::getPeople()
{
return People;//Error Here (No sutable user defined conversion)
}
I want get people to return a set<Person>
but am unsure how.
set
is the sorting algorithm that theset
uses to organize itself, so if you were to try and convert aset
to another type ofset
with a different sorting algorithm (the default in this case would beless<People>
, i.e.,person1 < person2
), I wouldn't necessarily expect to get the same set - it would be sorted differently. Is that what you intend to do - you want the same set sorted in a different way?