473,395 Members | 1,762 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,395 software developers and data experts.

accumulate: variant

mickey0
142 100+
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....
Expand|Select|Wrap|Line Numbers
  1. class Value {    
  2. public:
  3.     double _value;
  4.     bool _missed;
  5.         bool getMissed() const { return _missed; }
  6.         //other methods....
  7. };
  8. class Other {
  9.     vector<Value> _values;
  10.     static double sum_values(const double& accum, const Value& right) {
  11.      if ( right.getMissed() ) return accum;
  12.      return accum + right._value;
  13.     }
  14.     void computeMean() {
  15.           double mean = std::accumulate( _values.begin(), _values.end(), 0.0,   
  16.           Other::sum_values );
  17.     }
  18. };
  19.  
My accumulate compute the sum properly but HOW can I retrive the numbers summed???

Thanks,
Aug 22 '08 #1
3 1645
weaknessforcats
9,208 Expert Mod 8TB
Maybe as you sum the Values you could push_back the Value into a vector that you could return.

BTW: Your sum_values is a re-code of the std::accumulates algorithm.
Aug 22 '08 #2
mickey0
142 100+
yes but there is this line too: "if ( right.getMissed() )"
I don't know how code your idea, because I don't usually use accumulate and alghorithms; could you write me an example, please?

thanks,
Aug 22 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Matt Smith | last post by:
Hi, all. Just a quick question, when setting a COM process to read a value from a pre-defined register index, I think, I have to change the variable that the value will be returned to (as I have...
0
by: Matt Smith | last post by:
Hi, all. Just a quick question, when setting a COM process to read a value from a pre-defined register index, I think, I have to change the variable that the value will be returned to (as I have...
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...
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...
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...
19
by: Jon Davis | last post by:
Hi guys! Just wanted to let you all know that I created a Variant structure, inspired by the old VB6 days. This is written in C#, but you can build a CLR/.NET class library assembly and reference...
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:
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: 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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.