std::common_type(std::chrono::duration) (3) - Linux Manuals
std::common_type(std::chrono::duration): std::common_type(std::chrono::duration)
Command to display std::common_type(std::chrono::duration)
manual in Linux: $ man 3 std::common_type(std::chrono::duration)
NAME
std::common_type(std::chrono::duration) - std::common_type(std::chrono::duration)
Synopsis
template <class Rep1, class Period1, class Rep2, class Period2>
struct common_type<std::chrono::duration<Rep1, Period1>,
std::chrono::duration<Rep2, Period2>> { (since C++11)
typedef std::chrono::duration<
typename std::common_type<Rep1, Rep2>::type, /*see note*/> type;
};
Exposes the type named type, which is the common type of two std::chrono::durations.
Note
The period of the resulting duration is the greatest common divisor of Period1 and Period2.
Example
// Run this code
#include <iostream>
#include <chrono>
// std::chrono already finds the greatest common divisor,
// likely using std::common_type<>. We make the type
// deduction externally.
template <typename T,typename S>
auto durationDiff(const T& t, const S& s) -> typename std::common_type<T,S>::type
{
typedef typename std::common_type<T,S>::type Common;
return Common(t) - Common(s);
}
int main()
{
typedef std::chrono::milliseconds milliseconds;
typedef std::chrono::microseconds microseconds;
auto ms = milliseconds(30);
auto us = microseconds(1100);
std::cout << ms.count() << "ms - " << us.count() << "us = "
<< durationDiff(ms,us).count() << "\n";
}
Output:
30ms - 1100us = 28900
See also
common_type determines the common type of a group of types
(class template)
(C++11)
Pages related to std::common_type(std::chrono::duration)
- std::common_type(std::chrono::time_point) (3) - std::common_type(std::chrono::time_point)
- std::common_type (3) - std::common_type
- std::common_comparison_category (3) - std::common_comparison_category
- std::common_reference (3) - std::common_reference
- std::comp_ellint_1,std::comp_ellint_1f,std::comp_ellint_1l (3) - std::comp_ellint_1,std::comp_ellint_1f,std::comp_ellint_1l
- std::comp_ellint_2,std::comp_ellint_2f,std::comp_ellint_2l (3) - std::comp_ellint_2,std::comp_ellint_2f,std::comp_ellint_2l
- std::comp_ellint_3,std::comp_ellint_3f,std::comp_ellint_3l (3) - std::comp_ellint_3,std::comp_ellint_3f,std::comp_ellint_3l
- std::compare_3way (3) - std::compare_3way
- std::complex (3) - std::complex
- std::complex<T>::complex (3) - std::complex<T>::complex
- std::complex<T>::imag (3) - std::complex<T>::imag
- std::complex<T>::operator+(unary),operator-(unary) (3) - std::complex<T>::operator+(unary),operator-(unary)