std::chrono::duration_cast
Da cppreference.com.
|
|
Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.
La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
<metanoindex/>
<tbody> </tbody> template <class ToDuration, class Rep, class Period> constexpr ToDuration duration_cast(const duration<Rep,Period>& d); |
(dal C++11) | |
Converte un std::chrono::duration per una durata di
ToDuration tipo diverso.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.
Conversioni implicite non sono utilizzati. Moltiplicazioni e divisioni vengono evitate quando possibile, se è noto al momento della compilazione che uno o più parametri sono
1. I calcoli sono fatti nel più ampio tipo disponibile e convertito nel tipo di risultato solo quando hai finito.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.
Parametri
| d | - | durata da convertire
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. |
Valore di ritorno
d convertito in una durata di 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.
Note
La funzione non prende parte alla risoluzione di sovraccarico a meno
ToDuration è un'istanza di 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.
Fusione tra virgola mobile o tra durate durate interi in cui il periodo di sorgente è esattamente divisibile per il periodo di destinazione (ad esempio, ora a minuti) può essere eseguita implicitamente, non
duration_cast è necessaria.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.
Esempio
Questo esempio misura il tempo di esecuzione di una funzione
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";
}
Output:
f() took 1000 milliseconds