« first day (1537 days earlier)      last day (1307 days later) » 

7:39 AM
Hi folks, what is the underlying concept of the following mechanism?

we are not allowed to do `Person& p = Person();` but `const Person& p = Person();`.


Any comment and suggestion are welcome. Please ping me if you answer this question. I usually don't scan all comments after posting comments here because it is hard to know which comments correspond to which comment. Thank you in advance.
 
@NotAZoomedImage the compiler will probably tell you that it can't bind an rvalue reference (temporary) to a mutable reference
 
"initial value of reference to non-const must be lvalue" compiler error in visual studio commmunity.
 
 
5 hours later…
12:47 PM
How to convert std::filesystem::file_time_type to std::chrono::system_clock::time_point? Preferably without going through time_t - there is such a solution on SO, but I assume there is a shorter way. C++ 17.
 
nwp
std::chrono::clock_cast looks great for what you want, but that's a C++20 feature.
 
@nwp, Thanks, I know, but I need a C++ 17 solution :/ Any ideas?
 
nwp
It looks like time_t is the most reasonable C++17 solution.
 
But there is no guarantee that it will be Unix time. A colleague just told me on one of the platforms he works with file time starts in 1900.
 
nwp
That doesn't matter. It doesn't need to be Unix time.
time_since_epoch() seems to be the only way to compare clocks. You don't necessarily have to convert that to a time_t. Maybe unsigned long long in milliseconds is enough.
You could calculate the offset of clocks once and just add that difference. And chances are the offset is 0 and the system only has 1 clock.
 
1:02 PM
I believe different clocks may have different epochs?
 
nwp
They are allowed to. In practice though I would not expect that to be the case.
 
In other words, the trick from this example is the way to convert between clocks, and there is no better way pre-C++17? stackoverflow.com/a/61067330/634821
 
nwp
I would calculate - TP::clock::now() + system_clock::now() only once and put it in a constant. I'm pretty sure you can do that.
 
1:28 PM
I think I understand what you mean, but it is only needed once anyway:
template <typename TimePoint>
std::chrono::system_clock::time_point to_system_type_point(TimePoint tp)
{
using namespace std::chrono;
return time_point_cast<system_clock::duration>(tp - TimePoint::clock::now() + system_clock::now());
}
 
nwp
It was more about keeping inaccuracies constant than saving lines.
 
Oh, you mean caching this difference value? Understood.
 

« first day (1537 days earlier)      last day (1307 days later) »