L
Lambda
I'm writing a function to partition a vector according to a predicate.
For example:
vector<string>::size_type partition(vector<Student_info> &v)
{
vector<string>::size_type i, j;
i = -1;
j = v.size();
while (true)
{
cout << i << ' ' << j << endl;
do ++i; while (i <= v.size() - 1 && !fgrade(v));
do --j; while (j >= 0 && fgrade(v[j]));
if (i > j)
break;
exchange(v, i, j);
}
return i;
}
fgrade will return true if the student's grade is less than 60.
I want the i is the position one before the first element
and j is the position one after the last element.
But size_type is an unsigned int, so it's wrong to assign -1 to i, i
will become a larger integer.
If I change type of i and j to int, I'll encounter signed/unsigned
mismatch problem.
What can I do to handle this situation?
For example:
vector<string>::size_type partition(vector<Student_info> &v)
{
vector<string>::size_type i, j;
i = -1;
j = v.size();
while (true)
{
cout << i << ' ' << j << endl;
do ++i; while (i <= v.size() - 1 && !fgrade(v));
do --j; while (j >= 0 && fgrade(v[j]));
if (i > j)
break;
exchange(v, i, j);
}
return i;
}
fgrade will return true if the student's grade is less than 60.
I want the i is the position one before the first element
and j is the position one after the last element.
But size_type is an unsigned int, so it's wrong to assign -1 to i, i
will become a larger integer.
If I change type of i and j to int, I'll encounter signed/unsigned
mismatch problem.
What can I do to handle this situation?