Espaces de noms
Variantes
Affichages
Actions

std::chrono::duration_cast

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

 
 
 
 
std::chrono::duration
Les fonctions membres
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%=
Tiers fonctions
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
Classes d'aide
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);
(depuis C++11)
Convertit un std::chrono::duration à une durée de ToDuration type différent .
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.
Pas de conversions implicites sont utilisées. Multiplications et divisions sont évités autant que possible, si elle est connue au moment de la compilation d'un ou plusieurs paramètres sont 1. Calculs sont effectués dans le plus grand type disponible et convertie au type de résultat que lorsque vous avez terminé .
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.

Sommaire

[modifier] Paramètres

d -
durée à convertir
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.

[modifier] Retourne la valeur

d converti en un type de durée de ToDuration .
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.

[modifier] Notes

La fonction ne participe pas à la résolution de surcharge à moins ToDuration est une instance de 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.
Coulée en virgule flottante entre des durées ou des durées entières entre la période où la source est exactement divisible par la période cible (par exemple heures à quelques minutes) peut être effectuée implicite, aucune duration_cast est nécessaire .
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 implicite, 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.

[modifier] Exemple

Cet exemple mesurer le temps d'exécution d'une fonction
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";
}

Résultat :

f() took 1000 milliseconds