updated result_of documentation

[SVN r64695]
This commit is contained in:
Daniel Walker 2010-08-09 16:07:20 +00:00
parent a4b8043e68
commit 94b91e8c92

View File

@ -151,37 +151,96 @@ void f() {
<code>result_of&lt;F(T1, T2, ..., <code>result_of&lt;F(T1, T2, ...,
T<em>N</em>)&gt;::type</code> defines the result type T<em>N</em>)&gt;::type</code> defines the result type
of the expression <code>f(t1, t2, of the expression <code>f(t1, t2,
...,t<em>N</em>)</code>. The implementation permits ...,t<em>N</em>)</code>. This implementation permits
the type <code>F</code> to be a function pointer, the type <code>F</code> to be a function pointer,
function reference, member function pointer, or class function reference, member function pointer, or class
type.</p> <p>If your compiler does not support type. By default, <em>N</em> may be any value between 0 and
<code>decltype</code>, then when <code>F</code> is a 10. To change the upper limit, define the macro
class type with a member type <code>result_type</code>, <code>BOOST_RESULT_OF_NUM_ARGS</code> to the maximum
value for <em>N</em>. Class template <code>result_of</code>
resides in the header <code>&lt;<a
href="../../boost/utility/result_of.hpp">boost/utility/result_of.hpp</a>&gt;</code>.</p>
<p>If your compiler supports <code>decltype</code>,
then you can enable automatic result type deduction by
defining the macro <code>BOOST_RESULT_OF_USE_DECLTYPE</code>,
as in the following example.</p>
<blockquote>
<pre>#define BOOST_RESULT_OF_USE_DECLTYPE
#include &lt;boost/utility/result_of.hpp&gt;
struct functor {
template&lt;class T&gt;
T operator()(T x)
{
return x;
}
};
typedef boost::result_of&lt;
functor(int)
&gt;::type type;</pre>
</blockquote>
<p>If your compiler does not support
<code>decltype</code>, then automatic result type
deduction of function objects is not
possible. Instead, <code>result_of</code>
uses the following protocol to allow the programmer to
specify a type. When <code>F</code> is a class type with a
member type <code>result_type</code>,
<code>result_of&lt;F(T1, T2, ..., <code>result_of&lt;F(T1, T2, ...,
T<em>N</em>)&gt;</code> is T<em>N</em>)&gt;</code> is
<code>F::result_type</code>. When <code>F</code> <code>F::result_type</code>. When <code>F</code> does
does not contain <code>result_type</code>, not contain <code>result_type</code>,
<code>result_of&lt;F(T1, T2, ..., <code>result_of&lt;F(T1, T2, ...,
T<em>N</em>)&gt;</code> is <code>F::result&lt;F(T1, T<em>N</em>)&gt;</code> is <code>F::result&lt;F(T1,
T2, ..., T<em>N</em>)&gt;::type</code> when T2, ..., T<em>N</em>)&gt;::type</code> when
<code><em>N</em> &gt; 0</code> or <code>void</code> <code><em>N</em> &gt; 0</code> or <code>void</code>
when <code><em>N</em> = 0</code>. For additional when <code><em>N</em> = 0</code>. Note that it is the
information about <code>result_of</code>, see the responsibility of the programmer to ensure that
C++ Library Technical Report, <a function objects accurately advertise their result
href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf">N1836</a>, type via this protocol, as in the following
or, for motivation and design rationale, the <code>result_of</code> <a example.</p>
href="http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1454.html">proposal</a>.</p>
<p>Class template <code>result_of</code> resides in <blockquote>
the header <code>&lt;<a <pre>struct functor {
href="../../boost/utility/result_of.hpp">boost/utility/result_of.hpp</a>&gt;</code>. By template&lt;class&gt; struct result;
default, <em>N</em> may be any value between 0 and
10. To change the upper limit, define the macro template&lt;class F, class T&gt;
<code>BOOST_RESULT_OF_NUM_ARGS</code> to the maximum struct result&lt;F(T)&gt; {
value for <em>N</em>.</p> typedef T type;
};
template&lt;class T&gt;
T operator()(T x)
{
return x;
}
};
typedef boost::result_of&lt;
functor(int)
&gt;::type type;</pre>
</blockquote>
<a name="BOOST_NO_RESULT_OF"></a> <a name="BOOST_NO_RESULT_OF"></a>
<p>This implementation of <code>result_of</code> requires class template partial specialization, the ability to parse function types properly, and support for SFINAE. If <code>result_of</code> is not supported by your compiler, including the header <code>boost/utility/result_of.hpp</code> will define the macro <code>BOOST_NO_RESULT_OF</code>. Contributed by Doug Gregor.</p> <p>This implementation of <code>result_of</code>
requires class template partial specialization, the
ability to parse function types properly, and support
for SFINAE. If <code>result_of</code> is not supported
by your compiler, including the header
<code>boost/utility/result_of.hpp</code> will
define the macro <code>BOOST_NO_RESULT_OF</code>.</p>
<p>For additional information
about <code>result_of</code>, see the C++ Library
Technical Report,
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf">N1836</a>,
or, for motivation and design rationale,
the <code>result_of</code> <a href="http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1454.html">proposal</a>.</p>
Contributed by Doug Gregor.</p>
<h2>Class templates for the Base-from-Member Idiom</h2> <h2>Class templates for the Base-from-Member Idiom</h2>
<p>See <a href="base_from_member.html">separate documentation</a>.</p> <p>See <a href="base_from_member.html">separate documentation</a>.</p>