Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > How to assign -...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 16 Topic 45163 of 48002
Post > Topic >>

How to assign -1 to size_type?

by Lambda <stephenhsu9@[EMAIL PROTECTED] > Apr 20, 2008 at 01:48 AM

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[i]));
		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?
 




 16 Posts in Topic:
How to assign -1 to size_type?
Lambda <stephenhsu9@[E  2008-04-20 01:48:43 
Re: How to assign -1 to size_type?
Ian Collins <ian-news@  2008-04-20 21:03:10 
Re: How to assign -1 to size_type?
Kai-Uwe Bux <jkherciue  2008-04-20 05:09:29 
Re: How to assign -1 to size_type?
Lambda <stephenhsu9@[E  2008-04-20 02:17:00 
Re: How to assign -1 to size_type?
"Bo Persson" &l  2008-04-20 13:11:38 
Re: How to assign -1 to size_type?
Kai-Uwe Bux <jkherciue  2008-04-20 07:21:49 
Re: How to assign -1 to size_type?
Lambda <stephenhsu9@[E  2008-04-20 04:57:37 
Re: How to assign -1 to size_type?
Lambda <stephenhsu9@[E  2008-04-20 05:08:30 
Re: How to assign -1 to size_type?
utab <umut.tabak@[EMAI  2008-04-20 05:34:36 
Re: How to assign -1 to size_type?
James Kanze <james.kan  2008-04-20 09:08:52 
Re: How to assign -1 to size_type?
James Kanze <james.kan  2008-04-20 09:16:56 
Re: How to assign -1 to size_type?
Kai-Uwe Bux <jkherciue  2008-04-20 13:05:01 
Re: How to assign -1 to size_type?
James Kanze <james.kan  2008-04-20 09:22:39 
Re: How to assign -1 to size_type?
Andrey Tarasevich <and  2008-04-20 13:09:51 
Re: How to assign -1 to size_type?
Lambda <stephenhsu9@[E  2008-04-20 19:55:58 
Re: How to assign -1 to size_type?
Lambda <stephenhsu9@[E  2008-04-20 20:08:29 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Oct 12 14:18:03 CDT 2008.