<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1225: C++0x result_of issue </title>
<meta property="og:title" content="Issue 1225: C++0x result_of issue ">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1225.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="1225"><a href="lwg-defects.html#1225">1225</a>. C++0x <code>result_of</code> issue </h3>
<p><b>Section:</b> 99 [func.ret] <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Sebastian Gesemann <b>Opened:</b> 2009-10-05 <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.ret">issues</a> in [func.ret].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p>
I think the text about <code>std::result_of</code> could be a little more precise.
Quoting from
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2960.pdf">N2960</a>...
</p>

<blockquote>
<p>
99 [func.ret] Function object return types
</p>

<pre>
template&lt;class&gt; class result_of;

template&lt;class Fn, class... ArgTypes&gt;
class result_of&lt;Fn(ArgTypes...)&gt; {
public:
  typedef <i>see below</i> type;
};
</pre>

<p>
Given an rvalue <code>fn</code> of type <code>Fn</code> and values <code>t1, t2,
..., tN</code> of types <code>T1, T2, ... TN</code> in <code>ArgTypes</code>
respectivly, the <code>type</code> member is the result type of the
expression <code>fn(t1,t2,...,tN)</code>. the values <code>ti</code> are lvalues
when the corresponding type <code>Ti</code> is an lvalue-reference type, and
rvalues otherwise.
</p>
</blockquote>

<p>
This text doesn't seem to consider lvalue reference types for <code>Fn</code>.
Also, it's not clear whether this class template can be used for
"SFINAE" like <code>std::enable_if</code>. Example:
</p>

<blockquote><pre>
template&lt;typename Fn, typename... Args&gt;
typename std::result_of&lt;Fn(Args...)&gt;::type
apply(Fn &amp;&amp; fn, Args &amp;&amp; ...args)
{
  // Fn may be an lvalue reference, too
  return std::forward&lt;Fn&gt;(fn)(std::forward&lt;Args&gt;(args)...);
}
</pre></blockquote>

<p>
Either <code>std::result_of&lt;...&gt;</code> can be instantiated and simply may not have
a typedef "<code>type</code>" (--&gt;SFINAE) or instantiating the class template for
some type combinations will be a "hard" compile-time error.
</p>

<p><i>[
2010-02-14 Daniel adds:
]</i></p>


<blockquote><p>
This issue should be considered resolved by <a href="lwg-defects.html#1255" title="declval should be added to the library (Status: C++11)">1255</a><sup><a href="https://cplusplus.github.io/LWG/issue1255" title="Latest snapshot">(i)</a></sup> and <a href="lwg-defects.html#1270" title="result_of should be moved to &lt;type_traits&gt; (Status: C++11)">1270</a><sup><a href="https://cplusplus.github.io/LWG/issue1270" title="Latest snapshot">(i)</a></sup>.  The wish to change <code>result_of</code> into a compiler-support
trait was beyond the actual intention of the submitter Sebastian.
</p></blockquote>

<p><i>[
2010 Pittsburgh:  Moved to <del>NAD Editorial</del><ins>Resolved</ins>, rationale added below.
]</i></p>




<p><b>Rationale:</b></p>
<p>
Solved by <a href="lwg-defects.html#1270" title="result_of should be moved to &lt;type_traits&gt; (Status: C++11)">1270</a><sup><a href="https://cplusplus.github.io/LWG/issue1270" title="Latest snapshot">(i)</a></sup>.
</p>


<p id="res-1225"><b>Proposed resolution:</b></p>

<p><i>[
These changes will require compiler support
]</i></p>


<p>
Change 99 [func.ret]:
</p>

<blockquote><pre>
template&lt;class&gt; class result_of; // <i>undefined</i>

template&lt;class Fn, class... ArgTypes&gt;
class result_of&lt;Fn(ArgTypes...)&gt; {
public:
  <del>typedef</del> <i>see below</i> <del>type;</del>
};
</pre>

<p><del>
Given an rvalue <code>fn</code> of type <code>Fn</code> and values <code>t1, t2,
..., tN</code> of types <code>T1, T2, ... TN</code> in <code>ArgTypes</code>
respectivly, the <code>type</code> member is the result type of the
expression <code>fn(t1,t2,...,tN)</code>. the values <code>ti</code> are lvalues
when the corresponding type <code>Ti</code> is an lvalue-reference type, and
rvalues otherwise.
</del></p>

<p>
<ins>The class template <code>result_of</code> shall meet the requirements of a
<i>TransformationTrait</i>: Given the types <code>Fn</code>, <code>T1</code>, <code>T2</code>, ..., <code>TN</code> every
template specialization <code>result_of&lt;Fn(T1,T2,...,TN)&gt;</code> shall define the
member typedef type equivalent to <code>decltype(<i>RE</i>)</code> if and only if
the expression <code><i>RE</i></code>
</ins></p>

<blockquote><pre><ins>
value&lt;Fn&gt;() ( value&lt;T1&gt;(), value&lt;T2&gt;(), ... value&lt;TN&gt;()  )
</ins></pre></blockquote>

<p><ins>
would be well-formed. Otherwise, there shall be no member typedef
<code>type</code> defined.
</ins></p>

</blockquote>
 
<p><i>[
The <code>value&lt;&gt;</code> helper function is a utility Daniel Kr&uuml;gler
proposed in
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2958.html">N2958</a>.
]</i></p>






</body>
</html>
