File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -520,6 +520,29 @@ struct CompactSizeFormatter
520
520
}
521
521
};
522
522
523
+ template <typename U, bool LOSSY = false >
524
+ struct ChronoFormatter {
525
+ template <typename Stream, typename Tp>
526
+ void Unser (Stream& s, Tp& tp)
527
+ {
528
+ U u;
529
+ s >> u;
530
+ // Lossy deserialization does not make sense, so force Wnarrowing
531
+ tp = Tp{typename Tp::duration{typename Tp::duration::rep{u}}};
532
+ }
533
+ template <typename Stream, typename Tp>
534
+ void Ser (Stream& s, Tp tp)
535
+ {
536
+ if constexpr (LOSSY) {
537
+ s << U (tp.time_since_epoch ().count ());
538
+ } else {
539
+ s << U{tp.time_since_epoch ().count ()};
540
+ }
541
+ }
542
+ };
543
+ template <typename U>
544
+ using LossyChronoFormatter = ChronoFormatter<U, true >;
545
+
523
546
class CompactSizeWriter
524
547
{
525
548
protected:
You can’t perform that action at this time.
0 commit comments