<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1059: Usage of no longer existing FunctionType concept</title>
<meta property="og:title" content="Issue 1059: Usage of no longer existing FunctionType concept">
<meta property="og:description" content="C++ library issue. Status: NAD Concepts">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1059.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#NAD_Concepts">NAD Concepts</a> status.</em></p>
<h3 id="1059"><a href="lwg-closed.html#1059">1059</a>. Usage of no longer existing FunctionType concept</h3>
<p><b>Section:</b> 22.10.17.3 <a href="https://wg21.link/func.wrap.func">[func.wrap.func]</a> <b>Status:</b> <a href="lwg-active.html#NAD_Concepts">NAD Concepts</a>
 <b>Submitter:</b> Daniel Kr&uuml;gler <b>Opened:</b> 2009-03-13 <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#func.wrap.func">issues</a> in [func.wrap.func].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#NAD Concepts">NAD Concepts</a> status.</p>
<p><b>Discussion:</b></p>
<p>
Due to a deliberate core language decision, the earlier called
"foundation" concept <code>std::FunctionType</code> had been removed in
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2773.pdf">N2773</a>
shortly
before the first "conceptualized" version of the WP
(<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf">N2798</a>)
had been
prepared. This caused a break of the library, which already used this
concept in the adapted definition of <code>std::function</code>
(22.10 <a href="https://wg21.link/function.objects">[function.objects]</a>/2, header <code>&lt;functional&gt;</code> synopsis and
22.10.17.3 <a href="https://wg21.link/func.wrap.func">[func.wrap.func]</a>).
</p>
<p>
A simple fix would be to either (a) make <code>std::function</code>'s primary template
unconstrained or to (b) add constraints based on existing (support) concepts.
A more advanced fix would (c) introduce a new library concept.
</p>
<p>
The big disadvantage of (a) is, that users can define templates which
cause compiler errors during instantiation time because of under-constrainedness
and would thus violate the basic advantage of constrained
code.
</p>
<p>
For (b), the ideal constraints for <code>std::function</code>'s template parameter would
be one which excludes everything else but the single provided partial
specialization that matches every "free function" type (i.e. any function
type w/o cv-qualifier-seq and w/o ref-qualifier).
Expressing such a type as as single requirement would be written as
</p>
<blockquote><pre>
template&lt;typename T&gt;
requires ReferentType&lt;T&gt; // Eliminate cv void and function types with cv-qual-seq
                         //   or ref-qual (depending on core issue #749)
      &amp;&amp; PointeeType&lt;T&gt;  // Eliminate reference types
      &amp;&amp; !ObjectType&lt;T&gt;  // Eliminate object types
</pre></blockquote>
<p>
Just for completeness approach (c), which would make sense, if the
library has more reasons to constrain for free function types:
</p>
<blockquote><pre>
auto concept FreeFunctionType&lt;typename T&gt;
  : ReferentType&lt;T&gt;, PointeeType&lt;T&gt;, MemberPointeeType&lt;T&gt;
{
  requires !ObjectType&lt;T&gt;;
}
</pre></blockquote>
<p>
I mention that approach because I expect that free function types belong
to the most natural type categories for every days coders. Potential
candidates in the library are <code>addressof</code> and class template <code>packaged_task</code>.
</p>

<p><i>[
Batavia (2009-05):
]</i></p>

<blockquote>
<p>
Alisdair would prefer to have a core-supported <code>FunctionType</code> concept
in order that any future changes be automatically correct
without need for a library solution to catch up;
he points to type traits as a precedent.
Further, he believes that a published concept can't in the future
be changed.
</p>
<p>
Bill feels this category of entity would change sufficiently slowly
that he would be willing to take the risk.
</p>
<p>
Of the discussed solutions, we tend toward option (c).
We like the idea of having a complete taxonomy of native types,
and perhaps erred in trimming the set.
</p>
<p>
We would like to have this issue reviewed by Core and would like
their feedback.  Move to Open.
</p>
</blockquote>


<p id="res-1059"><b>Proposed resolution:</b></p>
<ol>
<li>
<p>
Change in 22.10 <a href="https://wg21.link/function.objects">[function.objects]</a>/2, Header <code>&lt;functional&gt;</code> synopsis:
</p>
<blockquote><pre>
// 20.6.16 polymorphic function wrappers:
class bad_function_call;
template&lt;<del>FunctionType</del><ins>ReferentType F</ins>&gt;
<ins>requires PointeeType&lt;F&gt; &amp;&amp; !ObjectType&lt;F&gt;</ins>
class function; // undefined
</pre></blockquote>
</li>
<li>
<p>
Change in 22.10.17.3 <a href="https://wg21.link/func.wrap.func">[func.wrap.func]</a>:
</p>
<blockquote><pre>
namespace std {
template&lt;<del>FunctionType</del><ins>ReferentType F</ins>&gt;
<ins>requires PointeeType&lt;F&gt; &amp;&amp; !ObjectType&lt;F&gt;</ins>
class function; // undefined
</pre></blockquote>
</li>
</ol>





</body>
</html>
