Share via


clock_time_conversion-Struktur

Ein Merkmal, das angibt, wie eine time_point Art von Uhr in eine andere konvertiert wird, während Standard den entsprechenden Zeitpunkt beibehalten.

Syntax

// C++20
1) template<class Dest, class Source> struct clock_time_conversion {};
2) template<class Clock> struct clock_time_conversion<Clock, Clock>;
3) template<> struct clock_time_conversion<system_clock, system_clock>;
4) template<> struct clock_time_conversion<utc_clock, utc_clock>;
5) template<> struct clock_time_conversion<system_clock, utc_clock>;
6) template<> struct clock_time_conversion<utc_clock, system_clock>;
7) template<class Clock> struct clock_time_conversion<Clock, system_clock>;
8) template<class Clock> struct clock_time_conversion<system_clock, Clock>;
9) template<class Clock> struct clock_time_conversion<Clock, utc_clock>;
10) template<class Clock> struct clock_time_conversion<utc_clock, Clock>;

Vorlagenparameter

Clock
Ein Uhrtyp, der von/in konvertiert werden soll.

Dest
Der Uhrtyp, in den konvertiert werden soll.

Source
Der Uhrtyp, aus dem konvertiert werden soll.

Die Merkmale stellen die folgenden Konvertierungen bereit:

1) Eine leere Struktur, die nur so definiert ist, dass sie spezialisiert werden kann.
2-4) Identitätskonvertierungen. Gibt die gleiche Uhr zurück, die Sie übergeben.
5-6) Konvertierung zwischen sys_time und utc_time Anrufen utc_clock::to_sys oder utc_clock::from_sys abhängig von der Richtung der Konvertierung.
7-8) Konvertierung zwischen sys_time und der angegebenen Uhr, wenn die angegebene Uhr unterstützt to_sys und from_sys, führt zu einem Aufruf Clock::to_sys oder Clock::from_sys, abhängig von der Richtung der Konvertierung.
9-10) Konvertierung zwischen utc_timeund der angegebenen Uhr, wenn die angegebene Uhr unterstützt from_utc und to_sys, führt zu einem Aufruf Clock::to_utc oder Clock::from_utc, abhängig von der Richtung der Konvertierung.

Mitglieder

Name Beschreibung
operator () Wandelt eine Uhr in eine time_point andere um.

Hinweise

In der Regel verwenden Sie diese Eigenschaft nicht direkt in Ihrem Code. Sie wird von der clock_cast Konvertierungsfunktion verwendet.

Anforderungen

Header<chrono>:

Namespace:std::chrono

Compileroption:/std:c++latest

operator()

Wandelt einen Von einem time_point Takttyp in einen anderen um, während Standard den entsprechenden Zeitpunkt beibehalten.

Syntax

1)
template <class Duration>
time_point<Clock, Duration> operator()(const time_point<Clock, Duration>& t) const;

2)
template <class Duration>
sys_time<Duration> operator()(const sys_time<Duration> & t) const;

3)
template <class Duration>
utc_time<Duration> operator()(const utc_time<Duration>& t) const;

4)
template <class Duration>
sys_time<Duration> operator()(const utc_time<Duration>& t) const;

5)
template <class Duration>
utc_time<Duration> operator()(const sys_time<Duration>& t) const;

Parameter

t Der time_point zu konvertierende Text.

Rückgabewert

1-3) Identitätskonvertierungen. Keine Konvertierung. Gibt ohne Änderungen zurück t .
4) Gibt zurück utc_clock::to_sys(t).
5) Gibt zurück utc_clock::from_sys(t).

Abzugslinien

Die folgenden Abzugslinien sind für template <class Duration> operator():

1)
template <class Duration> auto operator()(const sys_time<Duration>& t) const
    -> decltype(Clock::from_sys(t));

2)
template <class Duration> auto operator()(const time_point<SourceClock, Duration>& t) const
    -> decltype(Clock::to_sys(t));

3)
template <class Duration> auto operator()(const utc_time<Duration>& t) const
    -> decltype(Clock::from_utc(t));

4)
template <class Duration> auto operator()(const time_point<Clock, Duration>& t) const
    -> decltype(Clock::to_utc(t));

1) Nimmt nur bei Clock Unterstützung from_sys() und Rückgabe time_point<Clock, Duration>an der Überladungsauflösung teil.
2) Nimmt nur bei Clock Unterstützung to_sys() und Rückgabe sys_time<Duration>an der Überladungsauflösung teil.
3) Nimmt nur bei Clock Unterstützung from_utc() und Rückgabe time_point<Clock, Duration>an der Überladungsauflösung teil.
4) Nimmt nur bei Clock Unterstützung to_utc() und Rückgabe utc_time<Duration>an der Überladungsauflösung teil.

Beispiel: clock_time_conversion

#include <iostream>
#include <chrono>

using namespace std::chrono;

int main()
{
    auto sd = sys_days{ 2021y / July / 26 };
    auto time = clock_time_conversion<utc_clock, system_clock>{}(sd);
    std::cout << time << "\n";
    return 0;
}
2021-07-26 00:00:00

Siehe auch

<chrono>
clock_cast
Headerdateienreferenz