blob: 7c3341af415ca23b88b626dda521d8677f621259 [file] [log] [blame]
Brian Silverman57be3162018-08-04 23:36:33 -07001
2// (C) Copyright Tobias Schwinger
3//
4// Use modification and distribution are subject to the boost Software License,
5// Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt).
6
7//------------------------------------------------------------------------------
8//
9// Reimplementation of the Boost result_of utility (see [Gregor01] and
10// [Gregor02]).
11//
12//
13// Detailed description
14// ====================
15//
16// This example implements the functionality of the Boost result_of utility.
17// Because of FunctionTypes we get away without repetitive code and the Boost
18// Preprocessor library.
19//
20//
21// Bibliography
22// ============
23//
24// [Gregor01] Gregor, D. The Boost result_of utility
25// http://www.boost.org/libs/utility
26//
27// [Gregor02] Gregor, D. A uniform method for computing function object return
28// types (revision 1)
29// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1454.html
30
31#include <boost/function_types/result_type.hpp>
32#include <boost/function_types/is_callable_builtin.hpp>
33
34#include <boost/mpl/eval_if.hpp>
35#include <boost/mpl/has_xxx.hpp>
36
37namespace example
38{
39 namespace ft = boost::function_types;
40 namespace mpl = boost::mpl;
41
42 template<typename F> struct result_of;
43
44 namespace detail
45 {
46 BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type)
47
48 template<typename F>
49 struct result_type_member
50 {
51 typedef typename F::result_type type;
52 };
53
54 template<typename F, typename Desc>
55 struct result_member_template
56 {
57 typedef typename F::template result<Desc>::type type;
58 };
59
60#if !BOOST_WORKAROUND(__BORLANDC__,BOOST_TESTED_AT(0x564))
61 template<typename F>
62 struct result_member_template< F, F(void) >
63 {
64 typedef void type;
65 };
66#endif
67
68 template<typename F, typename Desc>
69 struct result_of_impl
70 : mpl::eval_if
71 < ft::is_callable_builtin<F>
72 , ft::result_type<F>
73 , mpl::eval_if
74 < has_result_type<F>
75 , result_type_member<F>
76 , result_member_template<F,Desc>
77 > >
78 { };
79 }
80
81 template<typename Desc>
82 struct result_of
83 : detail::result_of_impl< typename ft::result_type<Desc>::type, Desc >
84 { };
85}
86