https://rentry.org/PPP2_p334

// Code derived from Stroustrup's PPP2 book
// § 9.8 The Date class
//  -and beginning on p 334

#include <iostream>

#include "Chrono.h"

using std::cerr;
using std::cout;

int main()
try {
  Chrono::Date holiday{1978, Chrono::Month::jul, 4};  // initialization

  // note: these two functions give completely bogus stub "calculations" ATM...
  Chrono::Date d2 = Chrono::next_Sunday(holiday);
  Chrono::Day  d  = day_of_week(d2);

  cout << "holiday is " << holiday << " d2 is " << d2 << '\n';
  cout << d << '\n';

  // return holiday != d2;

} catch (Chrono::Date::Invalid const&) {
  cerr << "error: Invalid date\n";
  return 1;

} catch (...) {
  cerr << "Oops: unknown exception!\n";
  return 2;
}

build & run:

g++ -std=c++20 -O2 -Wall -pedantic ./ch_09/main_p334.cpp && ./a.out

PrevUp
Chrono.hChrono.cppchrono_helper.hchrono_helper.cpp

Edit
Pub: 06 Apr 2023 18:23 UTC
Edit: 03 May 2023 01:24 UTC
Views: 376