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++ > count and count...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 13 Topic 45551 of 47977
Post > Topic >>

count and count_if algorithms return type seem to insufficient for

by "subramanian100in@[EMAIL PROTECTED] India" <subramanian100in@[EMAIL PROTECTED] > Apr 26, 2008 at 07:35 PM

Below is my understanding about count algorithms.

Return type of count and count_if algorithms is
iterator_traits<InputIterator>::difference_type.

If the container contains more than 'difference_type' elements
satisfying the condition, then count and count_if algorithm cannot
return a value greater than 'difference_type'.

As an example, suppose maximum value of 'difference_type' is INT_MAX.
Then the corresponding maximum value of 'size_type' is UINT_MAX. Now
consider the declaration
vector<char> v;
where 'v' contains UINT_MAX elements each of which is 'a'.

Now if I do
count(v.begin(), v.end(), 'a')
then the actual count would be UINT_MAX but it cannot be represented
in 'difference_type' which is the return type of count algorithm.

So' won't we get erroneous results from count algorithms ?

I understand that difference_type is same as ptrdiff_t for
pointers(belonging to the same array) and size_type if same as size_t.
This means that the count algorithms can never return values from
ptrdiff_t + 1 upto size_t.

Is this understanding correct ?

If what I have mentioned is really a problem with count algorithms,
how should I count the elements in a container satisfying  the
condition for large number of elements(ie greater than
difference_type) ?

Kindly clarify.

Thanks
V.Subramanian
 




 13 Posts in Topic:
count and count_if algorithms return type seem to insufficient f
"subramanian100in@[E  2008-04-26 19:35:48 
Re: count and count_if algorithms return type seem to insufficie
Daniel Pitts <newsgrou  2008-04-26 23:09:35 
Re: count and count_if algorithms return type seem to insufficie
Kai-Uwe Bux <jkherciue  2008-04-27 04:55:42 
Re: count and count_if algorithms return type seem to insufficie
Pete Becker <pete@[EMA  2008-04-27 06:45:02 
Re: count and count_if algorithms return type seem to insufficie
Kai-Uwe Bux <jkherciue  2008-04-27 08:05:14 
Re: count and count_if algorithms return type seem to insufficie
Pete Becker <pete@[EMA  2008-04-27 10:29:04 
Re: count and count_if algorithms return type seem to insufficie
"kwikius" <a  2008-04-27 16:43:09 
Re: count and count_if algorithms return type seem to insufficie
Pete Becker <pete@[EMA  2008-04-27 11:48:19 
Re: count and count_if algorithms return type seem to insufficie
"kwikius" <a  2008-04-27 22:59:37 
Re: count and count_if algorithms return type seem to insufficie
Pete Becker <pete@[EMA  2008-04-28 07:10:40 
Re: count and count_if algorithms return type seem to insufficie
"kwikius" <a  2008-04-28 18:31:34 
Re: count and count_if algorithms return type seem to insufficie
Pete Becker <pete@[EMA  2008-04-28 14:15:00 
Re: count and count_if algorithms return type seem to insufficie
"Bo Persson" &l  2008-04-27 18:55:56 

Post A Reply:
  Go here to Signup

AddThis Feed Button


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

Contact
tan12V112 Sat Oct 11 8:33:14 CDT 2008.