- chrono[meta header]
- std::chrono[meta namespace]
- function template[meta id-type]
- cpp11[meta cpp]
namespace std {
namespace chrono {
// duration * N = duration
template <class Rep1, class Period, class Rep2>
duration<typename common_type<Rep1, Rep2>::type, Period>
constexpr operator*(const duration<Rep1, Period>& d, const Rep2& s); // (1)
// N * duration = duration
template <class Rep1, class Rep2, class Period>
duration<typename common_type<Rep1, Rep2>::type, Period>
constexpr operator*(const Rep1& s, const duration<Rep2, Period>& d); // (2)
}}
- common_type[link /reference/type_traits/common_type.md]
durationの乗算を行う
- (1) :
is_convertible_v
<const Rep2&,
common_type_t
<Rep1, Rep2>>
がtrue
であること - (2) :
is_convertible_v
<const Rep1&,
common_type_t
<Rep1, Rep2>>
がtrue
であること
using cd = duration<typename common_type<Rep1, Rep2>::type, Period>;
return cd(cd(d).count() * s);
- common_type[link /reference/type_traits/common_type.md]
- count[link /reference/chrono/duration/count.md]
#include <iostream>
#include <chrono>
using namespace std::chrono;
int main()
{
// duration * rep
{
seconds s = seconds(3) * 2;
std::cout << s.count() << std::endl;
milliseconds ms = milliseconds(2) * 3;
std::cout << ms.count() << std::endl;
}
// rep * duration
{
seconds s = 2 * seconds(3);
std::cout << s.count() << std::endl;
milliseconds ms = 3 * milliseconds(2);
std::cout << ms.count() << std::endl;
}
}
- count()[link count.md]
6
6
6
6
- C++11
- GCC: 4.6.1 [mark verified]
- Visual C++: 2012 [mark verified], 2013 [mark verified], 2015 [mark verified]