Function object: Difference between revisions

Content deleted Content added
No edit summary
Maintaining state: Prefer values to references (and use const where possible)
Line 140:
class CountFrom {
public:
CountFrom(int& count) : count_(count) {}
int operator()() { return count_++; }
 
private:
int& count_;
};
 
int main() {
const int state(10);
std::generate_n(std::ostream_iterator<int>(std::cout, "\n"), 11,
CountFrom(state));