<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1237: Constrained error_code&#47;error_condition members</title>
<meta property="og:title" content="Issue 1237: Constrained error_code&#47;error_condition members">
<meta property="og:description" content="C++ library issue. Status: C++11">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1237.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#C++11">C++11</a> status.</em></p>
<h3 id="1237"><a href="lwg-defects.html#1237">1237</a>. Constrained <code>error_code</code>&#47;<code>error_condition members</code></h3>
<p><b>Section:</b> 19.5 <a href="https://wg21.link/syserr">[syserr]</a> <b>Status:</b> <a href="lwg-active.html#C++11">C++11</a>
 <b>Submitter:</b> Daniel Kr&uuml;gler <b>Opened:</b> 2009-10-14 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#syserr">issues</a> in [syserr].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++11">C++11</a> status.</p>
<p><b>Discussion:</b></p>
<p>
I'm just reflecting on the now SFINAE-constrained constructors
and assignment operators of <code>error_code</code> and <code>error_condition</code>:
</p>
<p>
These are the <em>only</em> library components that are pro-actively
announcing that they are using <code>std::enable_if</code> as constraining tool,
which has IMO several disadvantages:
</p>

<ol>
<li>
<p>
With the availability of template default arguments and
decltype, using <code>enable_if</code> in the C++0x standard library, seems
unnecessary restricting implementation freedom. E.g. there
should be no need for a useless specification of a dummy
default function argument, which only confuses the reader.
A more reasonable implementation could e.g. be
</p>

<blockquote><pre>
template &lt;class ErrorCodeEnum
 class = typename enable_if&lt;is_error_code_enum&lt;ErrorCodeEnum&gt;::value&gt;::type&gt;
error_code(ErrorCodeEnum e);
</pre></blockquote>

<p>
As currently specified, the function signatures are so unreadable,
that errors quite easily happen, see e.g. <a href="lwg-defects.html#1229" title="error_code operator= typo (Status: Resolved)">1229</a><sup><a href="https://cplusplus.github.io/LWG/issue1229" title="Latest snapshot">(i)</a></sup>.
</p>
</li>

<li>
<p>
We have a <em>lot</em> of constrained functions in other places, that
now have a standard phrase that is easily understandable:
</p>

<blockquote><p>
<i>Remarks:</i> This constructor&#47;function shall participate in overload
resolution if and only if X.
</p></blockquote>

<p>
where X describes the condition. Why should these components deviate?
</p>
</li>

<li>
<p>
If <code>enable_if</code> would <em>not</em> be explicitly specified, the standard library
is much better prepared for the future. It would also be possible, that
libraries with partial support for not-yet-standard-concepts could provide
a much better diagnostic as is possible with <code>enable_if</code>. This again
would allow for experimental concept implementations in the wild,
which as a result would make concept standardization a much more
natural thing, similar to the way as templates were standardized
in C++.
</p>

<p>
In summary: I consider it as a library defect that <code>error_code</code> and
<code>error_condition</code> explicitly require a dependency to <code>enable_if</code> and
do limit implementation freedom and I volunteer to prepare a
corresponding resolution.
</p>
</li>
</ol>

<p><i>[
2009-10-18 Beman adds:
]</i></p>


<blockquote><p>
I support this proposed resolution, and thank Daniel for writing it up.
</p></blockquote>

<p><i>[
2009-10 Santa Cruz:
]</i></p>


<blockquote><p>
Moved to Ready.
</p></blockquote>



<p id="res-1237"><b>Proposed resolution:</b></p>
<p><i>[
Should this resolution be accepted, I recommend to resolve <a href="lwg-defects.html#1229" title="error_code operator= typo (Status: Resolved)">1229</a><sup><a href="https://cplusplus.github.io/LWG/issue1229" title="Latest snapshot">(i)</a></sup> as NAD
]</i></p>


<ol>
<li>
<p>
In 19.5.4.1 <a href="https://wg21.link/syserr.errcode.overview">[syserr.errcode.overview]</a>/1, class <code>error_code</code>,
change as indicated:
</p>

<blockquote><pre>
// 19.5.2.2 constructors:
error_code();
error_code(int val, const error_category&amp; cat);
template &lt;class ErrorCodeEnum&gt;
  error_code(ErrorCodeEnum e<del>,
    typename enable_if&lt;is_error_code_enum&lt;ErrorCodeEnum&gt;::value&gt;::type * = 0</del>);

// 19.5.2.3 modifiers:
void assign(int val, const error_category&amp; cat);
template &lt;class ErrorCodeEnum&gt;
  <del>typename enable_if&lt;is_error_code_enum&lt;ErrorCodeEnum&gt;::value&gt;::type</del><ins>error_code</ins>&amp;
    operator=(ErrorCodeEnum e);
void clear();
</pre></blockquote>
</li>

<li>
<p>
Change 19.5.4.2 <a href="https://wg21.link/syserr.errcode.constructors">[syserr.errcode.constructors]</a> around the prototype before p. 7:
</p>

<blockquote><pre>
template &lt;class ErrorCodeEnum&gt;
error_code(ErrorCodeEnum e<del>,
  typename enable_if&lt;is_error_code_enum&lt;ErrorCodeEnum&gt;::value&gt;::type * = 0</del>);
</pre>
<blockquote>
<p>
<ins><i>Remarks:</i> This constructor shall not participate in overload
resolution, unless
<code>is_error_code_enum&lt;ErrorCodeEnum&gt;::value == true</code>.</ins>
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>
Change 19.5.4.3 <a href="https://wg21.link/syserr.errcode.modifiers">[syserr.errcode.modifiers]</a> around the prototype before p. 3:
</p>

<blockquote><pre>
template &lt;class ErrorCodeEnum&gt;
  <del>typename enable_if&lt;is_error_code_enum&lt;ErrorCodeEnum&gt;::value&gt;::type</del><ins>error_code</ins>&amp;
    operator=(ErrorCodeEnum e);
</pre>

<blockquote><p>
<ins><i>Remarks:</i> This operator shall not participate in overload resolution, unless
<code>is_error_code_enum&lt;ErrorCodeEnum&gt;::value == true</code>.</ins>
</p></blockquote>
</blockquote>
</li>

<li>
<p>
In 19.5.5.1 <a href="https://wg21.link/syserr.errcondition.overview">[syserr.errcondition.overview]</a>/1, class <code>error_condition</code>, change
as indicated:
</p>

<blockquote><pre>
// 19.5.3.2 constructors:
error_condition();
error_condition(int val, const error_category&amp; cat);
template &lt;class ErrorConditionEnum&gt;
  error_condition(ErrorConditionEnum e<del>,
    typename enable_if&lt;is_error_condition_enum&lt;ErrorConditionEnum&gt;::type* = 0</del>);

// 19.5.3.3 modifiers:
void assign(int val, const error_category&amp; cat);
template&lt;<del>typename</del><ins>class</ins> ErrorConditionEnum&gt;
  <del>typename enable_if&lt;is_error_condition_enum&lt;ErrorConditionEnum&gt;, error_code&gt;::type</del><ins>error_condition</ins> &amp;
    operator=( ErrorConditionEnum e );
void clear();
</pre></blockquote>
</li>

<li>
<p>
Change 19.5.5.2 <a href="https://wg21.link/syserr.errcondition.constructors">[syserr.errcondition.constructors]</a> around the
prototype before p. 7:
</p>

<blockquote><pre>
template &lt;class ErrorConditionEnum&gt;
  error_condition(ErrorConditionEnum e<del>,
    typename enable_if&lt;is_error_condition_enum&lt;ErrorConditionEnum&gt;::value&gt;::type* = 0</del>);
</pre>
<blockquote><p>
<ins><i>Remarks:</i> This constructor shall not participate in overload
resolution, unless
<code>is_error_condition_enum&lt;ErrorConditionEnum&gt;::value == true</code>.</ins>
</p></blockquote>
</blockquote>
</li>

<li>
<p>
Change 19.5.5.3 <a href="https://wg21.link/syserr.errcondition.modifiers">[syserr.errcondition.modifiers]</a> around the
prototype before p. 3:
</p>

<blockquote><pre>
template &lt;class ErrorConditionEnum&gt;
  <del>typename enable_if&lt;is_error_condition_enum&lt;ErrorConditionEnum&gt;::value&gt;::type</del><ins>error_condition</ins>&amp;
    operator=(ErrorConditionEnum e);
</pre>

<blockquote>
<p>
<ins><i>Remarks:</i> This operator shall not participate in overload resolution, unless
<code>is_error_condition_enum&lt;ErrorConditionEnum&gt;::value == true</code>.</ins>
</p>

<p>
<i>Postcondition:</i> <code>*this == make_error_condition(e)</code>.
</p>

<p>
<ins><i>Returns:</i> <code>*this</code></ins>
</p>
</blockquote>
</blockquote>

</li>
</ol>






</body>
</html>
