c++ - is there a boost or stl function that implements conditional accumulation? -


I want to apply a code that adds a certain range, as long as it matches a certain condition Do not here my code is:

  int x [5]; Int Gateindex (Int. Valle) {Int Eye; Int xtotal = 0; For (i = 0; i <5; ++ i) {if (xtotal> break) break; Xtotal + = x [i]; } Came back; }   

I am using c ++ 03 function I came across the stall but I do not want to add everything. I want to add value until it is more than the input. The array is just an example and it can change a vector or whatever.

You can write your own here

  template & lt; Typename InputIterator, TypeName ElementType, TypeName PRECIC & gt; Const Element Type Cache (if first (finally (* first)) init + = * first; (first; = last; ++ before); (first; InputIterator; return init;}   

He also has one that takes a binary operation, if you want to do something extra besides.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -