F
Fab
Dear All,
I am quite experienced with C++ but here's something I can't recall and
forgive me if I just don't recognize the (possible) simplicity of my
question.
I have the following code
// Custom comparator for pair,
// compares only by the first field
struct compare_first
{
template <typename T>
bool operator() (const T& a, const T& b)
{
return a.first < b.first;
}
};
which is later used in a sort like this
std::sort(cellid_particleid.begin(), cellid_particleid.end(), compare_first());
The sort orders a list of particles according to their cell ID. The
std:air<unsigned int, unsigned int> contains cellID and particleID,
respectively.
Since the operator() is templated in the comparator, why does my code
still compile? I assume the struct hides the templation, but is this
taken care of in std::sort then?
Thanks + best
Fab
I am quite experienced with C++ but here's something I can't recall and
forgive me if I just don't recognize the (possible) simplicity of my
question.
I have the following code
// Custom comparator for pair,
// compares only by the first field
struct compare_first
{
template <typename T>
bool operator() (const T& a, const T& b)
{
return a.first < b.first;
}
};
which is later used in a sort like this
std::sort(cellid_particleid.begin(), cellid_particleid.end(), compare_first());
The sort orders a list of particles according to their cell ID. The
std:air<unsigned int, unsigned int> contains cellID and particleID,
respectively.
Since the operator() is templated in the comparator, why does my code
still compile? I assume the struct hides the templation, but is this
taken care of in std::sort then?
Thanks + best
Fab