In this example, we will bring everything we learned in this chapter into a simple demonstration that reads the system clock at an interval specified by the user. To accomplish this, the following inclusions and namespaces are needed:
#include <chrono>
#include <iostream>
#include <gsl/gsl>
#include <unistd.h>
using namespace std::chrono;
Like the examples throughout this chapter, a user-defined overload for std::ostream{} is provided to convert time_point{} into a standard C string, and then stream the result to stdout:
template<typename C, typename D>
std::ostream &
operator<<(std::ostream &os, std::chrono::time_point<C,D> &obj)
{
auto t = std::chrono::system_clock::to_time_t(obj);
return os << ctime(&t);
}
In our protected_main() function (which is a pattern used throughout...