mirror of
https://github.com/boostorg/utility.git
synced 2025-05-09 15:04:00 +00:00
updated result_of documentation
[SVN r64695]
This commit is contained in:
parent
a4b8043e68
commit
94b91e8c92
99
utility.htm
99
utility.htm
@ -151,37 +151,96 @@ void f() {
|
|||||||
<code>result_of<F(T1, T2, ...,
|
<code>result_of<F(T1, T2, ...,
|
||||||
T<em>N</em>)>::type</code> defines the result type
|
T<em>N</em>)>::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><<a
|
||||||
|
href="../../boost/utility/result_of.hpp">boost/utility/result_of.hpp</a>></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 <boost/utility/result_of.hpp>
|
||||||
|
|
||||||
|
struct functor {
|
||||||
|
template<class T>
|
||||||
|
T operator()(T x)
|
||||||
|
{
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef boost::result_of<
|
||||||
|
functor(int)
|
||||||
|
>::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<F(T1, T2, ...,
|
<code>result_of<F(T1, T2, ...,
|
||||||
T<em>N</em>)></code> is
|
T<em>N</em>)></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<F(T1, T2, ...,
|
<code>result_of<F(T1, T2, ...,
|
||||||
T<em>N</em>)></code> is <code>F::result<F(T1,
|
T<em>N</em>)></code> is <code>F::result<F(T1,
|
||||||
T2, ..., T<em>N</em>)>::type</code> when
|
T2, ..., T<em>N</em>)>::type</code> when
|
||||||
<code><em>N</em> > 0</code> or <code>void</code>
|
<code><em>N</em> > 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><<a
|
<pre>struct functor {
|
||||||
href="../../boost/utility/result_of.hpp">boost/utility/result_of.hpp</a>></code>. By
|
template<class> struct result;
|
||||||
default, <em>N</em> may be any value between 0 and
|
|
||||||
10. To change the upper limit, define the macro
|
template<class F, class T>
|
||||||
<code>BOOST_RESULT_OF_NUM_ARGS</code> to the maximum
|
struct result<F(T)> {
|
||||||
value for <em>N</em>.</p>
|
typedef T type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
T operator()(T x)
|
||||||
|
{
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef boost::result_of<
|
||||||
|
functor(int)
|
||||||
|
>::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>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user