Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/156.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ “单位”比率在哪里?_C++_Numeric_C++ Standard Library - Fatal编程技术网

C++ “单位”比率在哪里?

C++ “单位”比率在哪里?,c++,numeric,c++-standard-library,C++,Numeric,C++ Standard Library,为公制前缀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

为公制前缀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::比率。 我知道该单位没有正式的公制前缀名称,但这并不意味着它不存在。 在中没有提到单位前缀。所以我想知道:什么是处理“单位”比率的最典型方式?例如,当持续时间转换为整秒时

使用“单位”比率的最典型方式是什么

使用单位比率最实用的方法是不使用它

这有点像问什么是乘以1的最佳方法。你没有

例如,当持续时间转换为整秒时

您可以编写std::chrono::duration\u cast

std::ratio没有名称,因为您永远不需要它的名称。例如,std::duration已经有一个默认的时段std::ratio

如果您仍想为其命名,可以这样做:

using unit_ratio = std::ratio<1>;

您列出的只是一些别名。没有人会阻止你使用std::ratio或者给它取个名字。对不起,我完全不清楚你想解决什么问题。你能举一些代码作为例子,在那里你会使用单位比吗?为什么你想把秒转换成秒?因为你可以?但是任何关于秒的东西都不是1:1现在你必须提供它,因为你写了一个非常特殊的函数模板。该标准仅提供具有此默认值的函数模板,因此无需使用std::ratio。该标准解决了其模板的问题。如果一些用户做了一些不寻常的事情,这些用户必须解决它。极客琐事:将ratio放入C++11的提案的早期草案实际上有一个ratio的类型别名。我不记得我们叫它什么了。由于缺少度量名称,我们提前退出了它。