std::chrono::duration::duration
De 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. |
<metanoindex/>
<tbody> </tbody> constexpr duration() = default; |
(1) | |
duration(const duration&) = default; |
(2) | |
template <class Rep2> constexpr explicit duration(const Rep2& r); |
(3) | |
template <class Rep2, class Period2> constexpr duration(const duration<Rep2, Period2>& d); |
(4) | |
Constrói um novo
duration de uma das várias fontes de dados opcionais.Original:
Constructs a new
duration from one of several optional data sources.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.
1)
O construtor padrão é padrão.
Original:
The default constructor is defaulted.
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.
2)
O construtor de cópia é padrão (faz uma cópia bit a bit da contagem de carrapatos).
Original:
The copy constructor is defaulted (makes a bitwise copy of the tick count).
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.
3)
Constrói uma duração de carrapatos
r. Note-se que este construtor só participa na resolução de sobrecarga se Rep2 (o tipo de argumento) é implicitamente conversível para rep (o tipo de carrapatos esta duração) eOriginal:
Constructs a duration with
r ticks. Note that this constructor only participates in overload resolution if Rep2 (the argument type) is implicitly convertible to rep (the type of this duration's ticks) andThe 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.
std::chrono::treat_as_floating_point<rep>::valueé verdade, ouOriginal:std::chrono::treat_as_floating_point<rep>::valueis true, orThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.std::chrono::treat_as_floating_point<Rep2>::valueé falso.Original:std::chrono::treat_as_floating_point<Rep2>::valueis false.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
@ @ (Ou seja, uma duração com uma contagem de escala inteiro não pode ser construído a partir de um valor de ponto flutuante, mas com uma duração de uma contagem de escala de ponto flutuante pode ser construído a partir de um valor inteiro)
Original:
@@(that is, a duration with an integer tick count cannot be constructed from a floating-point value, but a duration with a floating-point tick count can be constructed from an integer value)
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.
4)
Constrói uma duração convertendo
d a um período adequado e contagem de carrapatos, como se por std::chrono::duration_cast<duration>(d).count(). A fim de evitar o truncamento durante a conversão, este construtor só participa na resolução de sobrecarga, se:Original:
Constructs a duration by converting
d to an appropriate period and tick count, as if by std::chrono::duration_cast<duration>(d).count(). In order to prevent truncation during conversion, this constructor only participates in overload resolution if: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.
std::chrono::treat_as_floating_point<rep>::value == true
@ @ Ou ambos:
Original:
@@ or both:
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.
std::ratio_divide<Period2, period>::den == 1, andstd::chrono::treat_as_floating_point<Rep2>::value == false.
@ @ (Isto é, tanto a duração usa ponto flutuante carrapatos, ou
Period2 é exatamente divisível por período)Original:
@@ (that is, either the duration uses floating-point ticks, or
Period2 is exactly divisible by period)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.
Parâmetros
| r | - | uma contagem de carrapatos
Original: a tick count The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| d | - | uma duração para copiar
Original: a duration to copy from The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Exemplo
O código a seguir mostra vários exemplos (ambos válidos e inválidos) de como construir durações:
Original:
The following code shows several examples (both valid and invalid) of how to construct durations:
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 <chrono>
int main()
{
std::chrono::hours h(1); // one hour
std::chrono::milliseconds ms{3}; // 3 milliseconds
std::chrono::duration<int, std::kilo> ks(3); // 3000 seconds
// error: treat_as_floating_point<int>::value == false,
// This duration allows whole tick counts only
// std::chrono::duration<int, std::kilo> d3(3.5);
// 30Hz clock using fractional ticks
std::chrono::duration<double, std::ratio<1, 30>> hz30(3.5);
// 3000 microseconds constructed from 3 milliseconds
std::chrono::microseconds us = ms;
// error: 1/1000000 is not divisible by 1/1000
// std::chrono::milliseconds ms2 = us
}
Veja também
atribui o conteúdo Original: assigns the contents The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (função pública membro) |