473,385 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

accumulate() usage

Hi,

I have a function with add elements of a STL list from 'start' to
'end'.
In the debugger, the size of the list is 2 and start is 0 and end is 1.
But it never goes itside 'do_add' and it just return 0. I expect it
just 'sum' the FIRST element (since start is 0 and end is 1).

Can you please tell me why is that?

_myList is a type of vector<int>
float getTotal(int start,int end) {
vector<int>::iterator beginItr = _myList.begin() + start;
vector<int>::iterator endItr = _myList.begin() + end;
return accumulate (beginItr, endItr, 0.0, do_add<int, float>());

}

Feb 2 '06 #1
1 2318
Al************@gmail.com wrote:
But it never goes itside 'do_add' and it just return 0. I expect it
just 'sum' the FIRST element (since start is 0 and end is 1).

Can you please tell me why is that?

_myList is a type of vector<int>
float getTotal(int start,int end) {
vector<int>::iterator beginItr = _myList.begin() + start;
vector<int>::iterator endItr = _myList.begin() + end;
return accumulate (beginItr, endItr, 0.0, do_add<int, float>());


This code works fine when I tried it (After adding necessary minimal
definitions and other stuff). Could you please give the complete code
which demonstrates the problem?

Feb 2 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Brian K. Michalk | last post by:
I have a perl app that is calculating the standard deviation of a 4000 element 16 bit integer array, that has large dynamic content. I.e, the range spans a significant portion of the 16 bits. I...
2
by: tomvr | last post by:
Hello I have noticed some 'weird' memory usage in a vb.net windows app The situation is as follows I have an app (heavy on images) with 2 forms (actually there are more forms and on starting...
14
by: Norm | last post by:
Hi, Each time the user selects an item from a combobox, I want that string to get appended to the values that were already selected. The result is that the combo is accumulating text each time...
8
by: John | last post by:
Hi, I have an application that receives data (floats) via a socket. My job is to receive the bytes, byte-swap them and convert them to floats, and make them available to the application. The...
2
by: benjamin_r | last post by:
I am trying to use the std::accumulate function. When I compile the following code I get: error C2780: '_Ty std::accumulate(_InIt,_InIt,_Ty,_Fn2)' : expects 4 arguments - 3 provided. It should...
5
by: cesco | last post by:
I have a set of pairs defined as follow: set< pair<UserEquipment*, double> > numberOfFreqSlotsToAdd; and I need to iterate through all the elements of the set in order accumulate the second...
1
by: yinglcs | last post by:
I have a function in STL which add the 'area' attribute of a list of Rect. template< class T1, class T2> class add_area_per_cent : public binary_function<T2, T1, T2> { public:...
7
by: Henrique A. Menarin | last post by:
I want to create a function _and so that I could write vector<boolasserts; //... bool b = _and(asserts); and it "anded" all the elements in the vector. I implemented it like this:
3
mickey0
by: mickey0 | last post by:
hello, I need to sum a vector and divide the sum by the number of element: if the filed _missed is "true", the value mustn't take into account.... class Value { public: double _value; bool...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.