fork download
  1. #include <iostream>
  2. #include <cassert>
  3.  
  4. struct day_of_year
  5. {
  6. day_of_year( int d = 1 ) : day(d) {}
  7.  
  8. operator int() const { return day ; }
  9.  
  10. static constexpr int MAX = 365 ;
  11.  
  12. day_of_year& operator++ () { ++day ; if( day > MAX ) day = 1 ; return *this ; }
  13. day_of_year operator++ (int) { day_of_year temp = *this ; ++*this ; return temp ; }
  14.  
  15. int day ;
  16. };
  17.  
  18. int main()
  19. {
  20. day_of_year d = 350 ;
  21. while( d > 1 ) std::cout << d++ << '\n' ;
  22. assert( d == 1 ) ;
  23. }
  24.  
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365