J
Jef Driesen
The number of items in my std::list is changed after sorting (using
std::list member function sort). I'm using MSVC6 and the actual (pseudo)
code is posted below. The output from size() is different before and
after the sort. If I remove the sorting (and nothing else), both numbers
remain the same.
int nmerged = 0;
do {
std::list<mum_pair> mregions;
// Add many items using push_back
mregions.push_back(...);
std::cout << mregions.size() << std::endl;
if (mregions.size()) {
// Sort the list
mregions.sort();
// Output first and last element.
std::cout << mregions.front() << "\t"
<< mregions.back() << std::endl;
}
std::cout << mregions.size() << std::endl;
// Update iteration count.
nmerged = ...;
} while (nmerged);
An item in the list is an std:air with an additional property lambda,
that is used as sorting criteria.
struct mum_pair : public std:air<mum_region*,mum_region*> {
double lambda;
mum_pair(mum_region*const A, mum_region*const B)
: std:air<mum_region*,mum_region*>(A,B), lambda(0.0) {};
mum_pair(mum_region*const A, mum_region*const B, double lambda)
: std:air<mum_region*,mum_region*>(A,B), lambda(lambda) {};
bool operator<(const mum_pair& rhs) const
{
return (lambda > rhs.lambda); // Sort descending.
}
};
std::list member function sort). I'm using MSVC6 and the actual (pseudo)
code is posted below. The output from size() is different before and
after the sort. If I remove the sorting (and nothing else), both numbers
remain the same.
int nmerged = 0;
do {
std::list<mum_pair> mregions;
// Add many items using push_back
mregions.push_back(...);
std::cout << mregions.size() << std::endl;
if (mregions.size()) {
// Sort the list
mregions.sort();
// Output first and last element.
std::cout << mregions.front() << "\t"
<< mregions.back() << std::endl;
}
std::cout << mregions.size() << std::endl;
// Update iteration count.
nmerged = ...;
} while (nmerged);
An item in the list is an std:air with an additional property lambda,
that is used as sorting criteria.
struct mum_pair : public std:air<mum_region*,mum_region*> {
double lambda;
mum_pair(mum_region*const A, mum_region*const B)
: std:air<mum_region*,mum_region*>(A,B), lambda(0.0) {};
mum_pair(mum_region*const A, mum_region*const B, double lambda)
: std:air<mum_region*,mum_region*>(A,B), lambda(lambda) {};
bool operator<(const mum_pair& rhs) const
{
return (lambda > rhs.lambda); // Sort descending.
}
};