Namensräume
Varianten
Aktionen

std::chrono::duration_cast

Aus cppreference.com
< cpp‎ | chrono‎ | duration

 
 
 
 
std::chrono::duration
Member-Funktionen
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
duration::duration
duration::operator=
duration::count
duration::zero
duration::min
duration::max
duration::operator+
duration::operator-
duration::operator++
duration::operator--
duration::operator+=
duration::operator-=
duration::operator*=
duration::operator/=
duration::operator%=
Non-Member-Funktionen
Original:
Non-member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
common_type
operator+
operator-
operator*
operator/
operator%
operator==
operator!=
operator<
operator<=
operator>
operator>=
duration_cast
Helper-Klassen
Original:
Helper classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
treat_as_floating_point
duration_values
 
template <class ToDuration, class Rep, class Period>
constexpr ToDuration duration_cast(const duration<Rep,Period>& d);
(seit C++11)
Konvertiert einen std::chrono::duration zu einer Dauer von unterschiedlichem Typ ToDuration .
Original:
Converts a std::chrono::duration to a duration of different type ToDuration.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Keine impliziten Konvertierungen verwendet werden. Multiplikationen und Divisionen vermieden werden, soweit möglich, wenn es bei der Kompilierung, dass ein oder mehrere Parameter 1 sind bekannt ist. Berechnungen werden in den unterschiedlichsten Art sind verfügbar gemacht und in die Ergebnis-Typ nur, wenn Sie fertig .
Original:
No implicit conversions are used. Multiplications and divisions are avoided where possible, if it is known at compile time that one or more parameters are 1. Computations are done in the widest type available and converted to the result type only when finished.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Inhaltsverzeichnis

[Bearbeiten] Parameter

d -
Dauer zu konvertieren
Original:
duration to convert
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[Bearbeiten] Rückgabewert

d einer Dauer vom Typ ToDuration überführt .
Original:
d converted to a duration of type ToDuration.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[Bearbeiten] Notes

Die Funktion ist nicht in der Überlast Beschlussfassung teilnehmen, es sei denn ToDuration ist eine Instanz der std::chrono::duration .
Original:
The function does not participate in the overload resolution unless ToDuration is an instance of std::chrono::duration.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Casting zwischen Floating-Point-Dauern oder zwischen Integer Dauern, wo die Quelle beträgt teilbar durch das Ziel Zeitraum (zB Stunden auf Minuten) kann implizit durchgeführt werden, wird kein duration_cast nötig .
Original:
Casting between floating-point durations or between integer durations where the source period is exactly divisible by the target period (e.g. hours to minutes) can be performed implizit, no duration_cast is needed.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[Bearbeiten] Beispiel

Dieses Beispiel misst die Ausführungszeit einer Funktion
Original:
This example measures the execution time of a function
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <iostream>
#include <chrono>
#include <thread>
 
void f()
{
    std::this_thread::sleep_for(std::chrono::seconds(1));
}
 
int main()
{
    auto t1 = std::chrono::high_resolution_clock::now();
    f();
    auto t2 = std::chrono::high_resolution_clock::now();
    std::cout << "f() took "
              << std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count()
              << " milliseconds\n";
}

Output:

f() took 1000 milliseconds