struct MyStruct
{
MyStruct(int n) : m_n(n){}
int m_n;
};
//...
std::vector<MyStruct*> vec2;
for (int i = 3; i >= 0; --i)
{
vec2.push_back(new MyStruct(i));
}
std::sort(vec2.begin(), vec2.end());
struct MyStruct
{
MyStruct(int n) : m_n(n){}
int m_n;
};
struct MyStructPredicate
{
bool operator()(const MyStruct* const & rhs, const MyStruct*const & lhs)
{
return rhs->m_n < lhs->m_n;
}
};
struct MyStructPredicate2
{
bool operator()(const MyStruct* rhs, const MyStruct* lhs)
{
return rhs->m_n < lhs->m_n;
}
};
//...
std::vector<MyStruct*> vec2;
for (int i = 3; i >= 0; --i)
{
vec2.push_back(new MyStruct(i));
}
std::sort(vec2.begin(), vec2.end(), MyStructPredicate());
std::sort(vec2.begin(), vec2.end(), MyStructPredicate2());
Clearly here I have added two predicates for sorting, both of which work perfectly well on their own. My question is simply which is the preferred signature of the predicate's operator(): I could not find any documentation suggesting which one to use, but I was recently told that "const references to pointers is unwarranted" in this case (which confused me) so tried to find documentation suggesting that the signature should be operator()(const T&, const T&)
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.