Generic programming using std::transform()

Pages: 12
closed account (L1bXjE8b)
I already have this header file with some of the operations built-in:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class MiniMax {
public:
  // Constructor
  MiniMax();

  // Observe a data value, updating the recorded min, max, and count values
  void observe (const int& t);

  // Retrieve the accumulated statistics so far
  int getCount() const  {return count;}  // # data values observed

  int getMin() const {return min;}         // smallest value observed
  int getMax() const {return max;}         // largest value observed



private:
  int min;
  int max;
  int count;
};



#endif 
5. for(int n: data) std::cout << n << ' '; std::cout << '\n';
The idea is to remove for loops. How could I get around the one you have in line 5?


that would be the wordier

1
2
std::copy(data.begin(), data.end(), std::ostream_iterator<int>(std::cout, " "));
std::cout << '\n';

Last edited on
Topic archived. No new replies allowed.
Pages: 12