Friday 15 May 2015

c++ - Histogram of integer without looping -


I was wandering if there is an STL algorithm that generates the same result of the following code:

This code outputs the histogram of my integer data with just one equal pre-defined bin size.

As I should know that I should avoid the loop, the equivalent of STL algorithms can be better than the majority of C ++ programmers.

Any suggestions?

Thanks in advance, Giuseppe

OK, you can at least clear the loop Can:

 for  (auto i: data) ++ calculation [i];  

You can (for example) use std :: for_each instead:

  std:: For_each (data.begin (), data.end (), [and count] (int i) {++ calculation [i];});  

... but it really does not like me more of improvement (if any).


No comments:

Post a Comment