std::common_type(std::chrono::duration)
cppreference.com
<tbody>
</tbody>
template <class Rep1, class Period1, class Rep2, class Period2> struct common_type<std::chrono::duration<Rep1, Period1>, std::chrono::duration<Rep2, Period2>> { typedef std::chrono::duration< typename std::common_type<Rep1, Rep2>::type, /* */> type; }; |
( C++11) | |
type, std::chrono::duration, Period1 Period2.
, Period1::num Period2::num Period1::den Period2::den.
#include <type_traits>
#include <iostream>
#include <chrono>
// std::chrono ,
// , std::common_type<>.
// .
template <typename T,typename S>
constexpr 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()
{
using namespace std::literals;
constexpr auto ms = 30ms;
constexpr auto us = 1100us;
constexpr auto diff = durationDiff(ms, us);
std::cout << ms << " - " << us << " = " << diff << '\n';
}
:
30ms - 1100us = 28900us
| std::common_type ( ) | |
(C++11) |
( ) |