namespace NAU{
// 帶單位的數量,
// Un_:表單位
// v: 多少個數量
// pul: 每個數量多少單位
template<class Un_, class TP_>
struct AU {
TP_ v;
TP_ pul;
AU(const TP_& v_ = TP_(0), const TP_& pul_ = TP_(1))
:v(v_),pul(pul_)
{}
TP_ ToNormal() const { return v * pul; } // 換算成正常單位值
};
void Demo() {
struct Second {};
AU<Second, float> milis(50.0f, 0.001f); // 50個1毫秒
printf("50個毫秒是: %f秒.\n", milis.ToNormal());
std::chrono::duration<float, std::ratio<1, 1000>> dura(50.0f); // 50個1毫秒
printf("50個毫秒是: %f秒.\n", std::chrono::duration_cast<std::chrono::duration<float>>(dura).count());
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/278991.html
標籤:C++ 語言
