fork(2) download
  1. #include <iostream>
  2. #include <iterator>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. struct magic { int a, b; };
  8. inline magic & operator ++ (magic &m) { return ++m.a, ++m.b, m; }
  9. inline double operator * (const magic &m) { return (double)m.a / m.b; }
  10. inline bool operator != (const magic &l, const magic &r) { return l.a != r.a || l.b != r.b; }
  11.  
  12. namespace std
  13. {
  14.  
  15. template<> struct iterator_traits<magic>
  16. {
  17. typedef magic value_type;
  18. typedef magic& reference;
  19. typedef std::input_iterator_tag iterator_category;
  20. };
  21.  
  22. }
  23. //inline magic *operator->(const magic &m) { return &m; }
  24.  
  25. //auto t = for_each(magic {44, 11}, magic {144, 111}, [](double x) { cout << x << '\n'; });
  26.  
  27. int main() {
  28. copy(magic {44, 11}, magic {144, 111}, ostream_iterator<double>(std::cout, "\n"));
  29. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
4
3.75
3.53846
3.35714
3.2
3.0625
2.94118
2.83333
2.73684
2.65
2.57143
2.5
2.43478
2.375
2.32
2.26923
2.22222
2.17857
2.13793
2.1
2.06452
2.03125
2
1.97059
1.94286
1.91667
1.89189
1.86842
1.84615
1.825
1.80488
1.78571
1.76744
1.75
1.73333
1.71739
1.70213
1.6875
1.67347
1.66
1.64706
1.63462
1.62264
1.61111
1.6
1.58929
1.57895
1.56897
1.55932
1.55
1.54098
1.53226
1.52381
1.51562
1.50769
1.5
1.49254
1.48529
1.47826
1.47143
1.46479
1.45833
1.45205
1.44595
1.44
1.43421
1.42857
1.42308
1.41772
1.4125
1.40741
1.40244
1.39759
1.39286
1.38824
1.38372
1.37931
1.375
1.37079
1.36667
1.36264
1.3587
1.35484
1.35106
1.34737
1.34375
1.34021
1.33673
1.33333
1.33
1.32673
1.32353
1.32039
1.31731
1.31429
1.31132
1.30841
1.30556
1.30275
1.3