<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2054: time_point constructors need to be constexpr</title>
<meta property="og:title" content="Issue 2054: time_point constructors need to be constexpr">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2054.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#Resolved">Resolved</a> status.</em></p>
<h3 id="2054"><a href="lwg-defects.html#2054">2054</a>. <code>time_point</code> constructors need to be <code>constexpr</code></h3>
<p><b>Section:</b> 30.6 <a href="https://wg21.link/time.point">[time.point]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Anthony Williams <b>Opened:</b> 2011-05-13 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p>
In 30.6 <a href="https://wg21.link/time.point">[time.point]</a>, <code>time_point::min()</code> and <code>time_point::max()</code> 
are listed as <code>constexpr</code>. However, <code>time_point</code> has no <code>constexpr</code> constructors, 
so is not a literal type, and so these functions cannot be <code>constexpr</code> without adding a 
<code>constexpr</code> constructor for implementation purposes.
<p/>
Proposed resolution: Add <code>constexpr</code> to the constructors of <code>time_point</code>. The effects of
the constructor template basically imply that the member function <code>time_since_epoch()</code> is
intended to be <code>constexpr</code> as well.
</p>

<p><i>[2012, Portland]</i></p>

<p>
Resolved by adopting paper <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3469">n3469</a>.
</p>



<p id="res-2054"><b>Proposed resolution:</b></p>
<p>This wording is relative to the FDIS.</p>
<ol>
<li><p>Alter the class template definition in 30.6 <a href="https://wg21.link/time.point">[time.point]</a> as follows:</p>
<blockquote><pre>
template &lt;class Clock, class Duration = typename Clock::duration&gt;
class time_point {
  [&hellip;]
public:
  <i>// 20.11.6.1, construct:</i>
  <ins>constexpr</ins> time_point(); <i>// has value epoch</i>
  <ins>constexpr</ins> explicit time_point(const duration&amp; d); <i>// same as time_point() + d</i>
  template &lt;class Duration2&gt;
    <ins>constexpr</ins> time_point(const time_point&lt;clock, Duration2&gt;&amp; t);

  <i>// 20.11.6.2, observer:</i>
  <ins>constexpr</ins> duration time_since_epoch() const;
  [&hellip;]
};
</pre></blockquote>
</li>

<li><p>Alter the declarations in 30.6.2 <a href="https://wg21.link/time.point.cons">[time.point.cons]</a>:</p>
<blockquote><pre>
<ins>constexpr</ins> time_point();
</pre><blockquote><p>
-1- <i>Effects</i>: Constructs an object of type <code>time_point</code>, initializing <code>d_</code> with <code>duration::zero()</code>. Such a
<code>time_point</code> object represents the epoch.
</p></blockquote></blockquote>
<blockquote><pre>
<ins>constexpr explicit</ins> time_point(const duration&amp; d);
</pre><blockquote><p>
-2- <i>Effects</i>: Constructs an object of type <code>time_point</code>, initializing <code>d_</code> with <code>d</code>. Such a 
<code>time_point</code> object represents the epoch <code>+ d</code>.
</p></blockquote></blockquote>
<blockquote><pre>
template &lt;class Duration2&gt;
  <ins>constexpr</ins> time_point(const time_point&lt;clock, Duration2&gt;&amp; t);
</pre><blockquote><p>
-3- <i>Remarks</i>: This constructor shall not participate in overload resolution unless <code>Duration2</code> is implicitly
convertible to <code>duration</code>.
<p/>
-4- <i>Effects</i>: Constructs an object of type <code>time_point</code>, initializing <code>d_</code> with <code>t.time_since_epoch()</code>.
</p></blockquote></blockquote>
</li>

<li><p>Alter the declaration in 30.6.3 <a href="https://wg21.link/time.point.observer">[time.point.observer]</a>:</p>
<blockquote><pre>
<ins>constexpr</ins> duration time_since_epoch() const;
</pre><blockquote><p>
-1- <i>Returns</i>: d_.
</p></blockquote></blockquote>
</li>
</ol>





</body>
</html>
