What is Projection as in the ranges library?

Projection is defined as a mapping of a set into a subset.In the ranges library the std::ranges::sort it is possible to define the ordering by a projection (which can be to a particular field address ). In this case, which is the set and which is the subset?


The code shows an example:

1
2
3
4
5
6
7
struct PhoneBookEntry
{
    std::string name;
    int number;
}

std::ranges::sort( phoneBookVector, {}, &PhoneBookEntry::number);


Is the mapping from thee whole object (PhoneBookEntry) to selecting a field member the projection? Which are the set and subset in this case?



Regards,
Juan
The projection would be an implicit function equivalent to [](const PhoneBookEntry &pbe){ return pbe.number; }, the set would be phoneBookVector, and the subset would be a sequence resulting from applying the projection to each element of the set. That's what I understand.
I think it comes from the relational world as in:


Projections - The ability to request only certain columns from the database when writing your query
Topic archived. No new replies allowed.