{"id":284090,"date":"2017-03-29T13:50:02","date_gmt":"2017-03-29T09:50:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=284090"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=284090","title":{"rendered":"\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 chrono (C++)"},"content":{"rendered":"<p>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u043a\u0430\u043a \u0441 \u0431\u0435\u0437\u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0439 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u043e\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043a \u043d\u0435\u0434\u043e\u0440\u0430\u0437\u0443\u043c\u0435\u043d\u0438\u044f\u043c \u0438 \u043e\u0448\u0438\u0431\u043a\u0430\u043c \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0435\u0434\u0438\u043d\u0438\u0446 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<blockquote><p><em>\u2013 \u0421\u043b\u0443\u0448\u0430\u0439, \u0442\u044b \u043d\u0435 \u043f\u043e\u043c\u043d\u0438\u0448\u044c, \u043c\u044b \u0432 sleep \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u0438\u043b\u0438 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u044b?<\/em><\/p>\n<p>  <em>\u2013 \u0411\u043b\u0438\u043d, \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0443 \u043c\u0435\u043d\u044f \u0432 \u0447\u0430\u0441\u0435 360 \u0441\u0435\u043a\u0443\u043d\u0434, \u043d\u043e\u043b\u044c \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u043b.<\/em><\/p><\/blockquote>\n<p>\u0414\u043b\u044f \u0438\u0437\u0431\u0435\u0436\u0430\u043d\u0438\u044f \u0442\u0430\u043a\u0438\u0445 \u043e\u0448\u0438\u0431\u043e\u043a \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 chrono (namespace std::chrono). \u041e\u043d\u0430 \u0431\u044b\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 C++11 \u0438 \u0434\u043e\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b\u0430\u0441\u044c \u0432 \u043f\u043e\u0437\u0434\u043d\u0438\u0445 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0430\u0445. \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0435 \u043b\u043e\u0433\u0438\u0447\u043d\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">using namespace std::chrono;  int find_answer_to_the_ultimate_question_of_life() {     \/\/\u041f\u043e\u0438\u0441\u043a \u043e\u0442\u0432\u0435\u0442\u0430     std::this_thread::sleep_for(5s); \/\/5 \u0441\u0435\u043a\u0443\u043d\u0434     return 42; }  std::future&lt;int&gt; f = std::async(find_answer_to_the_ultimate_question_of_life);  \/\/\u0416\u0434\u0435\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c 2.5 \u0441\u0435\u043a\u0443\u043d\u0434 if (f.wait_for(2500ms) == std::future_status::ready)     std::cout &lt;&lt; &quot;Answer is: &quot; &lt;&lt; f.get() &lt;&lt; &quot;\\n&quot;; else     std::cout &lt;&lt; &quot;Can't wait anymore\\n&quot;;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u2013 <code>duration<\/code>;<\/li>\n<li>\u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u2013 <code>time_point<\/code>;<\/li>\n<li>\u0442\u0430\u0439\u043c\u0435\u0440\u044b \u2013 <code>clock<\/code>.<\/li>\n<\/ul>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h2 id=\"stdratio\">std::ratio<\/h2>\n<p>  <\/p>\n<p>std::ratio \u2013 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 compile-time \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u0443\u044e \u0434\u0440\u043e\u0431\u044c. \u041e\u043d \u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a chrono, \u043d\u043e \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u044d\u0442\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443, \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043c\u0441\u044f \u0441 \u043d\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u0434\u0430\u043b\u0435\u0435 \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u043b \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">template&lt;     std::intmax_t Num,       \/\/\u0427\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c     std::intmax_t Denom = 1  \/\/\u0417\u043d\u0430\u043c\u0435\u043d\u0430\u0442\u0435\u043b\u044c &gt; class ratio;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0430\u0436\u043d\u043e, \u0447\u0442\u043e \u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c \u0438 \u0437\u043d\u0430\u043c\u0435\u043d\u0430\u0442\u0435\u043b\u044c \u2013 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0435 constexpr \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0438\u043f \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u042d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 (\u0447\u0438\u0441\u0442\u043e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439, helper class), \u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u043d\u0435 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439. \u041e\u043d \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \u0435\u0434\u0438\u043d\u0438\u0446 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0435\u0434\u0438\u043d\u0438\u0446\u0430\u043c\u0438 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0439:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">template&lt;class _Ratio&gt; class Length {     double length_; public:     explicit Length(double length) : length_(length) { }     double length() const { return length_; } };  Length&lt;Mm&gt; len1(127.0); Length&lt;Inches&gt; len2(5.0); Length&lt;Mm&gt; len3 = len1 + len2;<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0443\u0441\u0442\u044c \u043c\u0438\u043b\u043b\u0438\u043c\u0435\u0442\u0440 \u0431\u0443\u0434\u0435\u0442 \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u0435\u0434\u0438\u043d\u0438\u0446\u0435\u0439, \u0442\u043e\u0433\u0434\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">using Mm = std::ratio&lt;1&gt;; \/\/\u0417\u043d\u0430\u043c\u0435\u043d\u0430\u0442\u0435\u043b\u044c == 1 \/\/\u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u044b: using Inches = std::ratio&lt;254, 10&gt;; using Metre = std::ratio&lt;1000, 1&gt;;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u0435\u0434\u0438\u043d\u0438\u0446\u0435. \u041d\u043e, \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0435\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0430\u043c, \u0433\u0434\u0435 \u044d\u0442\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0443\u0436\u043d\u043e. \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u0435\u0442\u0440\u044b \u0432 \u043c\u0438\u043b\u043b\u0438\u043c\u0435\u0442\u0440\u044b \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u043e\u043f\u0430\u0441\u0430\u044f\u0441\u044c \u043f\u043e\u0442\u0435\u0440\u044c \u043f\u0440\u0438 \u043e\u043a\u0440\u0443\u0433\u043b\u0435\u043d\u0438\u0438, \u0447\u0435\u0433\u043e \u043d\u0435\u043b\u044c\u0437\u044f \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0431 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0441\u0432\u044f\u0437\u0438 \u0441 \u0432\u044b\u0448\u0435\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c, \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u0438\u0448\u044c \u0434\u043b\u044f \u043f\u043e\u043b\u043d\u043e\u0442\u044b \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u044f \u043f\u0440\u0438\u0432\u043e\u0436\u0443 \u043d\u0435 \u0441\u0430\u043c\u0443\u044e \u0443\u0434\u0430\u0447\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0437\u0430\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u0443\u044e:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">template&lt;class _Ratio1, class _Ratio2&gt; Length&lt;Mm&gt; operator+(const Length&lt;_Ratio1&gt; &amp;left, const Length&lt;_Ratio2&gt; &amp;right) {     double len =         left.length() \/ _Ratio1::den * _Ratio1::num +         right.length() \/ _Ratio2::den * _Ratio2::num;     return Length&lt;Mm&gt;((int)len); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043c\u0435\u0442\u0440\u044b \u043f\u0440\u0438 \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043c\u0435\u0442\u0440\u043e\u0432 \u0438 \u043a\u0438\u043b\u043e\u043c\u0435\u0442\u0440\u043e\u0432.<\/p>\n<p>  <\/p>\n<h2 id=\"duration---interval-vremeni\">duration \u2014 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/h2>\n<p>  <\/p>\n<p>\u0428\u0430\u0431\u043b\u043e\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 std::chrono::duration \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0438\u043f\u043e\u043c \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u0418\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432 chrono \u2014 \u044d\u0442\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432 (\u0432 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u0435 tick period). \u042d\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u0438\u043f\u043e\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <code>int64_t<\/code> \u0438\u043b\u0438 <code>float<\/code>. \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0438\u043e\u0434\u0430 \u0438\u0437\u043c\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445 \u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u0440\u043e\u0431\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e std::ratio.<\/p>\n<p>  <\/p>\n<p>\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u0443\u0436\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435. \u0422\u0438\u043f\u044b \u043c\u043e\u0433\u0443\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f\u0445<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">using nanoseconds = duration&lt;long long, nano&gt;; using microseconds  = duration&lt;long long, micro&gt;; using milliseconds = duration&lt;long long, milli&gt;; using seconds = duration&lt;long long&gt;; using minutes = duration&lt;int, ratio&lt;60&gt; &gt;; using hours = duration&lt;int, ratio&lt;3600&gt; &gt;;  \/\/\u041f\u0440\u0438\u0441\u0442\u0430\u0432\u043a\u0438 nano, micro, milli: using nano = ratio&lt;1, 1000000000&gt;; using micro = ratio&lt;1, 1000000&gt;; using milli = ratio&lt;1, 1000&gt;;<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u0432\u043e\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">using namespace std::chrono;  \/\/3-\u043c\u0438\u043d\u0443\u0442\u043d\u044b\u0435 \u043f\u0435\u0441\u043e\u0447\u043d\u044b\u0435 \u0447\u0430\u0441\u044b using Hourglass = duration&lt;long, std::ratio&lt;180&gt;&gt;; \/\/\u0438\u043b\u0438 using Hourglass =   duration&lt;long, std::ratio_multiply&lt;std::ratio&lt;3&gt;, minutes::period&gt;&gt;;  \/\/\u0410 \u043c\u043e\u0436\u0435\u0442 \u0432\u0430\u043c \u0443\u0434\u043e\u0431\u043d\u043e \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u043e 2.75 \u0441\u0435\u043a\u0443\u043d\u0434 using MyTimeUnit = duration&lt;long, std::ratio&lt;11, 4&gt;&gt;;  \/\/\u041d\u0435\u0446\u0435\u043b\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0435\u043a\u0443\u043d\u0434. \u0418\u043d\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u043e using fseconds = duration&lt;float&gt;;  \/\/\u0414\u043b\u044f \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u043e\u0439 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b using seconds16 = duration&lt;uint16_t&gt;;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043a\u0430\u043a \u0441 \u043d\u0438\u043c\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u041d\u0435\u044f\u0432\u043d\u0430\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0437\u0430\u043f\u0440\u0435\u0449\u0435\u043d\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">seconds s = 5; \/\/\u041e\u0448\u0438\u0431\u043a\u0430  void foo(minutes); foo(42); \/\/\u041e\u0448\u0438\u0431\u043a\u0430<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u043e\u043b\u044c\u043a\u043e \u044f\u0432\u043d\u0430\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">seconds s{8};  void foo(minutes); foo(minutes{42});<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0441\u0442\u0430\u0442\u0438, \u043f\u043e\u0447\u0435\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0444\u0438\u0433\u0443\u0440\u043d\u044b\u0435 \u0441\u043a\u043e\u0431\u043a\u0438 \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"https:\/\/stackoverflow.com\/questions\/18222926\/why-is-list-initialization-using-curly-braces-better-than-the-alternatives\">\u0437\u0434\u0435\u0441\u044c<\/a>. \u0412\u043a\u0440\u0430\u0442\u0446\u0435: \u0434\u043b\u044f \u0438\u0437\u0431\u0435\u0436\u0430\u043d\u0438\u044f \u043d\u0435\u044f\u0432\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0441 \u043f\u043e\u0442\u0435\u0440\u044f\u043c\u0438. \u0414\u043e\u0431\u0430\u0432\u043b\u044e \u0435\u0449\u0435 \u0441\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 <code>T x(F());<\/code> \u0432\u043c\u0435\u0441\u0442\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 x, \u0442\u0440\u0430\u043a\u0442\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0435\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0442\u0438\u043f\u0430 <code>F(*)()<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0435\u0439 <code>T<\/code>. \u0420\u0435\u0448\u0435\u043d\u0438\u0435: <code>T x{F()};<\/code> \u0438\u043b\u0438 <code>T x((F()));<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0412 C++14 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u044b \u0434\u043b\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0435\u0434\u0438\u043d\u0438\u0446:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">seconds s = 4min;  void foo(minutes); foo(42min);<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c, \u0432\u044b\u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">seconds time1 = 5min + 17s; minutes time2 = 2h - 15min; bool less = 59s &lt; 1min;<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0448\u0435, \u043c\u043e\u0436\u043d\u043e \u043d\u0435\u044f\u0432\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0447\u0430\u0441\u044b \u0432 \u043c\u0438\u043d\u0443\u0442\u044b, \u043c\u0438\u043d\u0443\u0442\u044b \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u044b, \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u0432 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0443 \u0438 \u0442. \u0434., \u043d\u043e \u043d\u0435 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">minutes time3 = 20s; \/\/\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 seconds time4 = 2s + 500ms; \/\/\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043d\u0435\u044f\u0432\u043d\u043e\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u043b\u044f \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u043e \u0435\u0441\u043b\u0438 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0446\u0435\u043b\u044b\u043c \u0447\u0438\u0441\u043b\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">\/\/(20\/15) \/ (1\/3) = 4. \u041e\u043a! duration&lt;long, std::ratio&lt;1, 3&gt;&gt; t1 = duration&lt;long, std::ratio&lt;20, 15&gt;&gt;{ 1 };<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u0442\u044c 2 \u0441\u043f\u043e\u0441\u043e\u0431\u0430: \u043e\u043a\u0440\u0443\u0433\u043b\u0435\u043d\u0438\u0435 \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a float-\u0442\u0438\u043f\u0443.<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">\/\/\u041e\u0442\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u043d\u0438\u0435 \u0434\u0440\u043e\u0431\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 - \u043e\u043a\u0440\u0443\u0433\u043b\u0435\u043d\u0438\u0435 \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u043d\u0443\u043b\u044f minutes m1 = duration_cast&lt;minutes&gt;(-100s); \/\/-1m  \/\/C++17. \u041e\u043a\u0440\u0443\u0433\u043b\u0435\u043d\u0438\u0435 \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u0433\u043e \u0446\u0435\u043b\u043e\u0433\u043e minutes m2 = round&lt;minutes&gt;(-100s); \/\/-2m  \/\/C++17. \u041e\u043a\u0440\u0443\u0433\u043b\u0435\u043d\u0438\u0435 \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u043f\u043b\u044e\u0441 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0441\u0442\u0438 minutes m3 = ceil&lt;minutes&gt;(-100s); \/\/-1m  \/\/C++17. \u041e\u043a\u0440\u0443\u0433\u043b\u0435\u043d\u0438\u0435 \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u043c\u0438\u043d\u0443\u0441 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0441\u0442\u0438 minutes m4 = floor&lt;minutes&gt;(-100s); \/\/-2m<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0442\u043e\u0440\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">using fminutes = duration&lt;float, minutes::period&gt;; fminutes m = -100s;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0434\u043b\u044f \u0432\u0430\u0441 \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u0435\u043a\u0443\u043d\u0434 \u0442\u0438\u043f\u043e\u043c uint64_t. \u041e\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">using seconds16 = duration&lt;uint16_t, seconds::period&gt;; seconds16 s = 15s;<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u043e \u0432\u044b \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043e\u043f\u0430\u0441\u0430\u0435\u0442\u0435\u0441\u044c \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0447\u0438\u0441\u043b\u0430\u043c\u0438. \u0412 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0435 \u0442\u0430\u043a\u043e\u0439 \u043d\u0435\u0442 (\u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435), \u043d\u043e \u0435\u0441\u0442\u044c \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u0422\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u0432 VS, \u0435\u0435 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">#include &lt;safeint.h&gt;  using sint = msl::utilities::SafeInt&lt;uint16_t&gt;; using safe_seconds16 = duration&lt;sint, seconds::period&gt;; safe_seconds16 ss = 60000s; try {     ss += 10000s; } catch (msl::utilities::SafeIntException e) {     \/\/\u041e\u0439 };<\/code><\/pre>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0438\u043b\u0438 \u0432 \u0444\u0430\u0439\u043b, \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c count():<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">seconds s = 15s; std::cout &lt;&lt; s.count() &lt;&lt; &quot;s\\n&quot;;<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u043e \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 count \u0434\u043b\u044f \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439!<\/p>\n<p>  <\/p>\n<h2 id=\"time_point---moment-vremeni\">time_point \u2014 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/h2>\n<p>  <\/p>\n<p>\u041a\u043b\u0430\u0441\u0441 time_point \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u041c\u043e\u043c\u0435\u043d\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043d \u043a\u0430\u043a \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u043d\u044b\u043c \u043d\u0430 \u043a\u0430\u043a\u043e\u043c-\u043b\u0438\u0431\u043e \u0442\u0430\u0439\u043c\u0435\u0440\u0435, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u043e\u0442\u0441\u0447\u0435\u0442\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0432\u044b \u0433\u043e\u0442\u043e\u0432\u0438\u0442\u0435 \u0441\u0443\u043f, \u043f\u043e\u043b\u044c\u0437\u0443\u044f\u0441\u044c \u0441\u0435\u043a\u0443\u043d\u0434\u043e\u043c\u0435\u0440\u043e\u043c, \u0442\u043e \u0432\u0430\u0448\u0438 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code>0 \u0441\u0435\u043a: \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043a\u0430\u0441\u0442\u0440\u044e\u043b\u044e \u043f\u0430\u0441\u0441\u0435\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043e\u0432\u043e\u0449\u0438 420 \u0441\u0435\u043a: \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u043a\u0430\u0440\u0442\u043e\u0444\u0435\u043b\u044c 1300 \u0441\u0435\u043a: \u0433\u043e\u0442\u043e\u0432\u043e<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410 \u0435\u0441\u043b\u0438 \u043f\u043e \u043c\u0438\u043d\u0443\u0442\u043d\u043e\u0439 \u0441\u0442\u0440\u0435\u043b\u043a\u0435 \u043d\u0430\u0441\u0442\u0435\u043d\u043d\u044b\u0445 \u0447\u0430\u0441\u043e\u0432, \u0442\u043e \u0442\u0435 \u0436\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0442\u0430\u043a\u0438\u043c\u0438:<\/p>\n<p>  <\/p>\n<pre><code>17 \u043c\u0438\u043d: \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043a\u0430\u0441\u0442\u0440\u044e\u043b\u044e \u043f\u0430\u0441\u0441\u0435\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043e\u0432\u043e\u0449\u0438 24 \u043c\u0438\u043d: \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u043a\u0430\u0440\u0442\u043e\u0444\u0435\u043b\u044c 39 \u043c\u0438\u043d: \u0433\u043e\u0442\u043e\u0432\u043e<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u0441\u0430\u043c \u043a\u043b\u0430\u0441\u0441:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">template&lt;     class Clock,     class Duration = typename Clock::duration &gt; class time_point;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0438\u043f \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430\u043c \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c, \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0442\u0430\u0439\u043c\u0435\u0440\u0443 Clock. \u0412 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 3 \u0442\u0430\u0439\u043c\u0435\u0440\u0430:<\/p>\n<p>  <\/p>\n<ol>\n<li>system_clock \u2013 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u041e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u043e\u0442 \u0442\u0430\u0439\u043c\u0435\u0440 \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432, \u0442\u0430\u043a \u043a\u0430\u043a \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u0432\u0440\u0435\u043c\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0438\u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438. \u041e\u0431\u044b\u0447\u043d\u043e \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043f\u0440\u043e\u0448\u0435\u0434\u0448\u0438\u0445 \u0441 01.01.1970, \u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043e.<\/li>\n<li>steady_clock \u2013 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u043c\u043e\u043d\u043e\u0442\u043e\u043d\u043d\u044b\u0435 \u0447\u0430\u0441\u044b, \u0442\u043e \u0435\u0441\u0442\u044c \u0445\u043e\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435 \u043f\u043e\u0434\u0432\u0435\u0440\u0436\u0435\u043d \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u043c. \u0425\u043e\u0440\u043e\u0448\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u0432. \u041e\u0431\u044b\u0447\u043d\u043e \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043f\u043e\u0441\u043b\u0435 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f.<\/li>\n<li>high_resolution_clock \u2013 \u0442\u0430\u0439\u043c\u0435\u0440 \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u043c \u043e\u0442\u0441\u0447\u0435\u0442\u043e\u0432, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u0435. \u041c\u043e\u0436\u0435\u0442 \u044f\u0432\u043b\u044f\u0442\u0441\u044f \u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c\u043e\u043c \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0445 (\u043f\u043e\u0447\u0442\u0438 \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u044d\u0442\u043e steady_clock).<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0423 Clock \u0435\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>is_steady<\/code>, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0437\u043d\u0430\u0442\u044c, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u0442\u0430\u0439\u043c\u0435\u0440 \u043c\u043e\u043d\u043e\u0442\u043e\u043d\u043d\u044b\u043c. \u0422\u0430\u043a\u0436\u0435 \u0443 Clock \u0435\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f now, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0430\u044f \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432 \u0432\u0438\u0434\u0435 time_point. \u0421\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 <code>time_point<\/code> \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0435\u043d, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u043e\u043c\u0435\u043d\u0442 \u0435\u0433\u043e \u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0442\u0441\u0447\u0435\u0442\u0430 \u043d\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0440\u043e\u0432\u0430\u043d \u0438 \u0438\u043c\u0435\u0435\u0442 \u043c\u0430\u043b\u043e \u0441\u043c\u044b\u0441\u043b\u0430. \u041d\u043e \u043a \u043d\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043c\u043e\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">time_point&lt;steady_clock&gt; start = steady_clock::now(); \/\/\u0438\u043b\u0438 steady_clock::time_point start = steady_clock::now(); \/\/\u0438\u043b\u0438 auto start = steady_clock::now();  foo(); if (steady_clock::now() &lt; start + 1s)     std::cout &lt;&lt; &quot;Less than a second!\\n&quot;;<\/code><\/pre>\n<p>  <\/p>\n<p><code>time_point<\/code> \u043d\u0435\u043b\u044c\u0437\u044f \u0441\u043b\u043e\u0436\u0438\u0442\u044c \u0441 <code>time_point<\/code>, \u0437\u0430\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0447\u0435\u0441\u0442\u044c, \u0447\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0434\u043b\u044f \u0437\u0430\u0441\u0435\u0447\u0435\u043d\u0438\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">auto start = steady_clock::now(); foo(); auto end = steady_clock::now(); auto elapsed = duration_cast&lt;milliseconds&gt;(end - start);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043f\u0440\u043e\u0448\u0435\u0434\u0448\u0438\u0439 \u0441 \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0442\u0441\u0447\u0435\u0442\u0430, \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c <code>time_since_epoch<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">auto now = system_clock::now(); system_clock::duration tse = now.time_since_epoch();<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>time_point<\/code> \u0432 \u0447\u0438\u0441\u043b\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u043b\u0438 \u0432\u044b\u0432\u043e\u0434\u0430 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d, \u043c\u043e\u0436\u043d\u043e \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u0421-\u0442\u0438\u043f time_t:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">auto now = system_clock::now(); time_t now_t = system_clock::to_time_t(now); auto now2 = system_clock::from_time_t(now_t);<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"vmesto-zaklyucheniya\">\u0412\u043c\u0435\u0441\u0442\u043e \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f<\/h2>\n<p>  <\/p>\n<p>\u0421\u0430\u043c\u044b\u0439 \u0447\u0430\u0441\u0442\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441: \u043a\u0430\u043a \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0432\u0440\u0435\u043c\u044f \u0438 \u0434\u0430\u0442\u0443 \u0432 \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u043c \u0432\u0438\u0434\u0435. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e chrono \u043d\u0438\u043a\u0430\u043a. \u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c \u0441 time_t \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/howardhinnant.github.io\/date\/date.html\">\u0434\u0440\u0443\u0433\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443<\/a> \u043e\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 chrono.<\/p>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/324984\/\"> https:\/\/habrahabr.ru\/post\/324984\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u043a\u0430\u043a \u0441 \u0431\u0435\u0437\u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0439 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u043e\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043a \u043d\u0435\u0434\u043e\u0440\u0430\u0437\u0443\u043c\u0435\u043d\u0438\u044f\u043c \u0438 \u043e\u0448\u0438\u0431\u043a\u0430\u043c \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0435\u0434\u0438\u043d\u0438\u0446 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<blockquote><p><em>\u2013 \u0421\u043b\u0443\u0448\u0430\u0439, \u0442\u044b \u043d\u0435 \u043f\u043e\u043c\u043d\u0438\u0448\u044c, \u043c\u044b \u0432 sleep \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u0438\u043b\u0438 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u044b?<\/em><\/p>\n<p>  <em>\u2013 \u0411\u043b\u0438\u043d, \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0443 \u043c\u0435\u043d\u044f \u0432 \u0447\u0430\u0441\u0435 360 \u0441\u0435\u043a\u0443\u043d\u0434, \u043d\u043e\u043b\u044c \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u043b.<\/em><\/p><\/blockquote>\n<p>\u0414\u043b\u044f \u0438\u0437\u0431\u0435\u0436\u0430\u043d\u0438\u044f \u0442\u0430\u043a\u0438\u0445 \u043e\u0448\u0438\u0431\u043e\u043a \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 chrono (namespace std::chrono). \u041e\u043d\u0430 \u0431\u044b\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 C++11 \u0438 \u0434\u043e\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b\u0430\u0441\u044c \u0432 \u043f\u043e\u0437\u0434\u043d\u0438\u0445 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0430\u0445. \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0435 \u043b\u043e\u0433\u0438\u0447\u043d\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">using namespace std::chrono;  int find_answer_to_the_ultimate_question_of_life() {     \/\/\u041f\u043e\u0438\u0441\u043a \u043e\u0442\u0432\u0435\u0442\u0430     std::this_thread::sleep_for(5s); \/\/5 \u0441\u0435\u043a\u0443\u043d\u0434     return 42; }  std::future&lt;int&gt; f = std::async(find_answer_to_the_ultimate_question_of_life);  \/\/\u0416\u0434\u0435\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c 2.5 \u0441\u0435\u043a\u0443\u043d\u0434 if (f.wait_for(2500ms) == std::future_status::ready)     std::cout &lt;&lt; &quot;Answer is: &quot; &lt;&lt; f.get() &lt;&lt; &quot;\\n&quot;; else     std::cout &lt;&lt; &quot;Can't wait anymore\\n&quot;;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u2013 <code>duration<\/code>;<\/li>\n<li>\u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u2013 <code>time_point<\/code>;<\/li>\n<li>\u0442\u0430\u0439\u043c\u0435\u0440\u044b \u2013 <code>clock<\/code>.<\/li>\n<\/ul>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-284090","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284090","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=284090"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284090\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=284090"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=284090"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=284090"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}