>Well u can always use STL's "for_each" for efficiency, readability, portability & usability.
for_each isn't nearly as useful as the propaganda suggests. Also, for_each would be a poor solution to the issue that this tip covers. A better solution would be generate_n, but that's still not as concise and easy to follow Consider:
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
using namespace std;
class increment {
int _i;
public:
increment(int start = 0): _i(start) {}
int operator()() { return _i++; }
};
int main()
{
vector<int> v;
generate_n(back_inserter(v), 5, increment(1));
copy(v.begin(), v.end(), ostream_iterator<int>(cout, " "));
cout<<endl;
cin.get();
} How is that better? You said for_each though, so let's look at that one too. Well, for_each requires a range for the input sequence, so you still need a temporary list, and getting the function to add to a vector isn't as trivial as you seem to think. Instead of suggesting things at random, why don't you try implementing the suggestion first to see how reasonable it is?
>it also make code less readable than the smallCaptialized form..
That's your opinion, and it's debatable.