Skip to content

Instantly share code, notes, and snippets.

@virtuosonic
Created September 23, 2022 08:03
Show Gist options
  • Save virtuosonic/5b7de5baa064bc239e0da8c6fb374fcd to your computer and use it in GitHub Desktop.
Save virtuosonic/5b7de5baa064bc239e0da8c6fb374fcd to your computer and use it in GitHub Desktop.
#include <iostream>
#include <chrono>
#include <thread>
#include <vector>
#include <algorithm>
#include <iterator>
#include <random>
using namespace std;
using namespace std::chrono;
using namespace std::literals::chrono_literals;
void print_time_point(time_point<system_clock> t)
{
auto ttp = system_clock::to_time_t(t);
cout << ctime(&ttp);
}
int main()
{
vector<time_point<system_clock>> arr;
cout << "adding time points\n";
for (auto i = 0 ; i < 10 ; ++i)
{
arr.push_back(system_clock::now());
this_thread::sleep_for(1s);
}
for_each(arr.begin(),arr.end(),print_time_point);
sort( arr.rbegin(),arr.rend());
for_each(arr.begin(),arr.end(),print_time_point);
auto result = min_element(arr.begin(),arr.end());
cout << "result\n";
print_time_point(*result);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment