std::chrono::duration<Rep,Period>:: duration
From cppreference.net
|
constexpr
duration
(
)
=
default
;
|
(1) | (C++11부터) |
|
duration
(
const
duration
&
)
=
default
;
|
(2) | (C++11부터) |
|
template
<
class
Rep2
>
constexpr explicit duration ( const Rep2 & r ) ; |
(3) | (C++11부터) |
|
template
<
class
Rep2,
class
Period2
>
constexpr duration ( const duration < Rep2, Period2 > & d ) ; |
(4) | (C++11부터) |
여러 선택적 데이터 소스 중 하나에서 새로운
duration
을 생성합니다.
1)
기본 생성자.
2)
복사 생성자.
3)
r
틱으로 duration을 생성합니다.
이 오버로드는 다음의 모든 조건이 만족될 때만 오버로드 해결에 참여합니다:
- is_convertible < const Rep2 & , Rep > :: value 가 true 인 경우.
- 다음 조건 중 하나 이상이 만족되는 경우: [1]
-
- std:: chrono :: treat_as_floating_point < Rep > :: value 가 true 인 경우.
- std:: chrono :: treat_as_floating_point < Rep2 > :: value 가 false 인 경우.
4)
적절한 주기와 틱 카운트로
d
를 변환하여 duration을 생성합니다. 마치
std::
chrono
::
duration_cast
<
duration
>
(
d
)
.
count
(
)
를 사용한 것처럼 동작합니다.
이 오버로드는 변환에서 오버플로가 발생하지 않고 다음 조건 중 하나가 충족되는 경우에만 오버로드 해결에 참여합니다:
[2]
- std:: chrono :: treat_as_floating_point < Rep > :: value 가 true 인 경우.
- 다음 모든 조건이 충족되는 경우:
-
- std:: ratio_divide < Period2, Period > :: den 가 1 인 경우.
- std:: chrono :: treat_as_floating_point < Rep2 > :: value 가 false 인 경우.
- ↑ 즉, 정수형 틱 카운트를 가진 duration은 부동소수점 값으로부터 생성될 수 없지만, 부동소수점 틱 카운트를 가진 duration은 정수 값으로부터 생성될 수 있습니다.
-
↑
즉, duration이 부동소수점 틱을 사용하거나,
Period2가Period로 정확히 나누어져야 합니다.
목차 |
매개변수
| r | - | 틱 카운트 |
| d | - | 복사할 지속 시간 |
예제
다음 코드는 duration을 구성하는 방법에 대한 여러 예시(유효한 것과 유효하지 않은 것 모두)를 보여줍니다:
이 코드 실행
#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 std::chrono::duration<double, std::milli> ms2 = us; // 3.0 milliseconds }
결함 보고서
다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.
| DR | 적용 대상 | 게시된 동작 | 올바른 동작 |
|---|---|---|---|
| LWG 2094 | C++11 |
오버로드
(4)
의 경우,
std::
ratio_divide
<
Period2, period
>
::
num
평가 시 오버플로우 발생 가능 std:: ratio_divide < Period2, period > :: den |
오버로드
(4)
는 이 경우
오버로드 해결에 참여하지 않음 |
| LWG 3050 | C++11 | 변환 가능성 제약 조건에서 비-const xvalue 사용 | const lvalue 사용으로 대체 |
참고 항목
|
내용을 할당
(public member function) |