VS11是steady_clock,稳定? [英] VS11 is steady_clock, steady?

查看:349
本文介绍了VS11是steady_clock,稳定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只注意到< chrono.h> 中的下列代码,这对我来说没有意义。

I just noticed the following code in <chrono.h>, which doesn't make sense to me.

struct system_clock
{
    static const bool is_monotonic = false; // retained
    static const bool is_steady = false;
};

class steady_clock
    : public system_clock
    {   // wraps monotonic clock
public:
    static const bool is_monotonic = true;  // retained
    static const bool is_steady = true;
    };

typedef steady_clock monotonic_clock;   // retained
typedef system_clock high_resolution_clock;

如果 steady_clock

How can steady_clock be steady when it simply derives from system_clock which is not steady?

推荐答案

来自 system_clock 实现,一个稳定的时钟来自一个不稳定的时钟(或单调的一个来自非单调的)一般是非常好的意义。

Ignoring bugs in Microsoft's implementation for the moment, having a steady clock derive from an unsteady one (or a monotonic one derive from a non-monotonic one) makes perfectly good sense in general.

这个是典型的is-a术语被阻碍的地方之一,你需要真正地考虑替代。特别是,情况不是一个稳定的时钟不是一个不稳定的时钟,所以派生是错误的。相反,情况是在任何情况下都可以用稳定的时钟代替不稳定的时钟,因此推导很好( is_monotonic )。

This is one of those places that the typical "is-a" terminology gets in the way, and you need to really think in terms of substitution instead. In particular, the situation is not "a steady clock is not an unsteady clock, so the derivation is wrong." Rather, the situation is "a steady clock can be substituted for an unsteady clock under any circumstances, so the derivation is fine" (and likewise for is_monotonic).

让我们考虑一个极端的例子 - 原子钟直接连接到你的计算机。它是单调的,大约像你希望得到的一样稳定。假设它的输出频率足够高(/分辨率),你可以使用它来代替你的系统可能拥有的任何/每隔一个时钟。

Let's consider an extreme example -- having an atomic clock connected directly to your computer. It's monotonic and about as steady as you can hope to get. Assuming its output is high enough frequency (/resolution), you could use it in place of essentially any/every other clock your system might have available.

这篇关于VS11是steady_clock,稳定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆