std::chrono::duration_cast
Da cppreference.com
![]() |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
template <class ToDuration, class Rep, class Period> constexpr ToDuration duration_cast(const duration<Rep,Period>& d); |
(desde C++11) | |
Converte um std::chrono::duration para uma duração de
ToDuration
tipo diferente.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.
You can help to correct and verify the translation. Click here for instructions.
Não conversões implícitas são usados. Multiplicações e divisões são evitados sempre que possível, se ele é conhecido em tempo de compilação que um ou mais parâmetros são 1. Os cálculos são feitos no mais amplo tipo disponível e convertido para o tipo de resultado apenas quando terminado.
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.
You can help to correct and verify the translation. Click here for instructions.
Índice |
[editar] Parâmetros
d | - | duração para converter
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. |
[editar] Valor de retorno
d
convertido para uma duração de ToDuration
tipo.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.
You can help to correct and verify the translation. Click here for instructions.
[editar] Notas
A função não participar na resolução de sobrecarga, a menos
ToDuration
é uma instância 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.
You can help to correct and verify the translation. Click here for instructions.
Fundição de ponto flutuante entre durações ou entre durações inteiros, onde o período de fonte é exatamente divisível por o período de destino (por exemplo, horas para minutos) pode ser realizada implicitamente, não duration_cast é necessário.
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 implicitamente, 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.
You can help to correct and verify the translation. Click here for instructions.
[editar] Exemplo
Este exemplo mede o tempo de execução de uma função
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.
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"; }
Saída:
f() took 1000 milliseconds