From 94b91e8c92b58ec400045f301f00e8c3ba512ad5 Mon Sep 17 00:00:00 2001 From: Daniel Walker Date: Mon, 9 Aug 2010 16:07:20 +0000 Subject: [PATCH] updated result_of documentation [SVN r64695] --- utility.htm | 99 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 79 insertions(+), 20 deletions(-) diff --git a/utility.htm b/utility.htm index d4c7205..328aff2 100644 --- a/utility.htm +++ b/utility.htm @@ -151,37 +151,96 @@ void f() { result_of<F(T1, T2, ..., TN)>::type defines the result type of the expression f(t1, t2, - ...,tN). The implementation permits + ...,tN). This implementation permits the type F to be a function pointer, function reference, member function pointer, or class - type.

If your compiler does not support - decltype, then when F is a - class type with a member type result_type, + type. By default, N may be any value between 0 and + 10. To change the upper limit, define the macro + BOOST_RESULT_OF_NUM_ARGS to the maximum + value for N. Class template result_of + resides in the header <boost/utility/result_of.hpp>.

+ +

If your compiler supports decltype, + then you can enable automatic result type deduction by + defining the macro BOOST_RESULT_OF_USE_DECLTYPE, + as in the following example.

+ +
+
#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;
+
+ +

If your compiler does not support + decltype, then automatic result type + deduction of function objects is not + possible. Instead, result_of + uses the following protocol to allow the programmer to + specify a type. When F is a class type with a + member type result_type, result_of<F(T1, T2, ..., TN)> is - F::result_type. When F - does not contain result_type, + F::result_type. When F does + not contain result_type, result_of<F(T1, T2, ..., TN)> is F::result<F(T1, T2, ..., TN)>::type when N > 0 or void - when N = 0. For additional - information about result_of, see the - C++ Library Technical Report, N1836, - or, for motivation and design rationale, the result_of proposal.

+ when N = 0. Note that it is the + responsibility of the programmer to ensure that + function objects accurately advertise their result + type via this protocol, as in the following + example.

-

Class template result_of resides in - the header <boost/utility/result_of.hpp>. By - default, N may be any value between 0 and - 10. To change the upper limit, define the macro - BOOST_RESULT_OF_NUM_ARGS to the maximum - value for N.

+
+
struct functor {
+    template<class> struct result;
+
+    template<class F, class T>
+    struct result<F(T)> {
+        typedef T type;
+    };
+
+    template<class T>
+    T operator()(T x)
+    {
+        return x;
+    }
+};
+
+typedef boost::result_of<
+    functor(int)
+>::type type;
+
-

This implementation of result_of requires class template partial specialization, the ability to parse function types properly, and support for SFINAE. If result_of is not supported by your compiler, including the header boost/utility/result_of.hpp will define the macro BOOST_NO_RESULT_OF. Contributed by Doug Gregor.

+

This implementation of result_of + requires class template partial specialization, the + ability to parse function types properly, and support + for SFINAE. If result_of is not supported + by your compiler, including the header + boost/utility/result_of.hpp will + define the macro BOOST_NO_RESULT_OF.

+ +

For additional information + about result_of, see the C++ Library + Technical Report, + N1836, + or, for motivation and design rationale, + the result_of proposal.

+ Contributed by Doug Gregor.

Class templates for the Base-from-Member Idiom

See separate documentation.