I was wandering if there is an STL algorithm that generates the same result of the following code:
std :: vector & lt; Int & gt; Information; Std :: vector & lt; Integer & gt; Counter (n); // I already know that all values in the data are between 0 and 0 and for N-1 (int i = 0; i & lt; data; size (); ++ i) counter [data] ] ++;
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