【发布时间】:2020-10-20 08:06:55
【问题描述】:
std::ratio 为公制前缀(centi、deci、deca、hecto)提供方便的 typedef。
yocto std::ratio<1, 1000000000000000000000000>, if std::intmax_t can represent the denominator
zepto std::ratio<1, 1000000000000000000000>, if std::intmax_t can represent the denominator
atto std::ratio<1, 1000000000000000000>
femto std::ratio<1, 1000000000000000>
pico std::ratio<1, 1000000000000>
nano std::ratio<1, 1000000000>
micro std::ratio<1, 1000000>
milli std::ratio<1, 1000>
centi std::ratio<1, 100>
deci std::ratio<1, 10>
deca std::ratio<10, 1>
hecto std::ratio<100, 1>
kilo std::ratio<1000, 1>
mega std::ratio<1000000, 1>
giga std::ratio<1000000000, 1>
tera std::ratio<1000000000000, 1>
peta std::ratio<1000000000000000, 1>
exa std::ratio<1000000000000000000, 1>
zetta std::ratio<1000000000000000000000, 1>, if std::intmax_t can represent the numerator
yotta std::ratio<1000000000000000000000000, 1>, if std::intmax_t can represent the numerator
缺少什么?嗯……单位比例std::ratio<1,1>。
我知道该单位没有官方的公制前缀名称,但这并不意味着它不存在。
在[ratio.si] 中没有提到单位前缀。所以我想知道:使用“单位”比率的最典型方式是什么?例如,当duration_cast-ing 到整秒时。
【问题讨论】:
-
您列出的只是一些别名。没有人会阻止你使用
std::ratio<1,1>或给它起个名字 -
对不起,对我来说完全不清楚您要解决什么问题。您能否展示一些代码作为示例,您将使用
unit_ratio? -
为什么要从秒转换为秒?因为你可以?
-
但任何秒数都不是 1:1
-
现在你必须提供它,因为你写了一个非常特殊的函数模板。该标准仅提供具有此默认值的函数模板,因此不需要
std::ratio<1, 1>。该标准解决了其模板的问题。如果某些用户做了不寻常的事情,这些用户必须解决它。
标签: c++ numeric c++-standard-library