blob: 7cc2ec6e9381e48ed3bfa0a63a9ac33bf9b25236 [file] [log] [blame]
Jeff Thompsona28eed82013-08-22 16:21:10 -07001// Boost result_of library
2
3// Copyright Douglas Gregor 2004. Use, modification and
4// distribution is subject to the Boost Software License, Version
5// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6// http://www.boost.org/LICENSE_1_0.txt)
7
8// For more information, see http://www.boost.org/libs/utility
9#ifndef BOOST_RESULT_OF_HPP
10#define BOOST_RESULT_OF_HPP
11
12#include <ndnboost/config.hpp>
13#include <ndnboost/preprocessor/cat.hpp>
14#include <ndnboost/preprocessor/iteration/iterate.hpp>
15#include <ndnboost/preprocessor/repetition/enum_params.hpp>
16#include <ndnboost/preprocessor/repetition/enum_trailing_params.hpp>
17#include <ndnboost/preprocessor/repetition/enum_binary_params.hpp>
18#include <ndnboost/preprocessor/repetition/enum_shifted_params.hpp>
19#include <ndnboost/preprocessor/facilities/intercept.hpp>
20#include <ndnboost/detail/workaround.hpp>
21#include <ndnboost/mpl/has_xxx.hpp>
22#include <ndnboost/mpl/if.hpp>
23#include <ndnboost/mpl/eval_if.hpp>
24#include <ndnboost/mpl/bool.hpp>
25#include <ndnboost/mpl/identity.hpp>
26#include <ndnboost/mpl/or.hpp>
27#include <ndnboost/type_traits/is_class.hpp>
28#include <ndnboost/type_traits/is_pointer.hpp>
29#include <ndnboost/type_traits/is_member_function_pointer.hpp>
30#include <ndnboost/type_traits/remove_cv.hpp>
31#include <ndnboost/type_traits/remove_reference.hpp>
32#include <ndnboost/utility/declval.hpp>
33#include <ndnboost/utility/enable_if.hpp>
34
35#ifndef BOOST_RESULT_OF_NUM_ARGS
36# define BOOST_RESULT_OF_NUM_ARGS 16
37#endif
38
39// Use the decltype-based version of result_of by default if the compiler
40// supports N3276 <http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2011/n3276.pdf>.
41// The user can force the choice by defining either BOOST_RESULT_OF_USE_DECLTYPE or
42// BOOST_RESULT_OF_USE_TR1, but not both!
43#if defined(BOOST_RESULT_OF_USE_DECLTYPE) && defined(BOOST_RESULT_OF_USE_TR1)
44# error Both BOOST_RESULT_OF_USE_DECLTYPE and BOOST_RESULT_OF_USE_TR1 cannot be defined at the same time.
45#endif
46
47#ifndef BOOST_RESULT_OF_USE_TR1
48# ifndef BOOST_RESULT_OF_USE_DECLTYPE
49# ifndef BOOST_NO_CXX11_DECLTYPE_N3276 // this implies !defined(BOOST_NO_CXX11_DECLTYPE)
50# define BOOST_RESULT_OF_USE_DECLTYPE
51# else
52# define BOOST_RESULT_OF_USE_TR1
53# endif
54# endif
55#endif
56
57namespace ndnboost {
58
59template<typename F> struct result_of;
60template<typename F> struct tr1_result_of; // a TR1-style implementation of result_of
61
62#if !defined(BOOST_NO_SFINAE) && !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
63namespace detail {
64
65BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type)
66
67template<typename F, typename FArgs, bool HasResultType> struct tr1_result_of_impl;
68
69#ifdef BOOST_NO_SFINAE_EXPR
70
71// There doesn't seem to be any other way to turn this off such that the presence of
72// the user-defined operator,() below doesn't cause spurious warning all over the place,
73// so unconditionally turn it off.
74#if BOOST_MSVC
75# pragma warning(disable: 4913) // user defined binary operator ',' exists but no overload could convert all operands, default built-in binary operator ',' used
76#endif
77
78struct result_of_private_type {};
79
80struct result_of_weird_type {
81 friend result_of_private_type operator,(result_of_private_type, result_of_weird_type);
82};
83
84typedef char result_of_yes_type; // sizeof(result_of_yes_type) == 1
85typedef char (&result_of_no_type)[2]; // sizeof(result_of_no_type) == 2
86
87template<typename T>
88result_of_no_type result_of_is_private_type(T const &);
89result_of_yes_type result_of_is_private_type(result_of_private_type);
90
91template<typename C>
92struct result_of_callable_class : C {
93 result_of_callable_class();
94 typedef result_of_private_type const &(*pfn_t)(...);
95 operator pfn_t() const volatile;
96};
97
98template<typename C>
99struct result_of_wrap_callable_class {
100 typedef result_of_callable_class<C> type;
101};
102
103template<typename C>
104struct result_of_wrap_callable_class<C const> {
105 typedef result_of_callable_class<C> const type;
106};
107
108template<typename C>
109struct result_of_wrap_callable_class<C volatile> {
110 typedef result_of_callable_class<C> volatile type;
111};
112
113template<typename C>
114struct result_of_wrap_callable_class<C const volatile> {
115 typedef result_of_callable_class<C> const volatile type;
116};
117
118template<typename C>
119struct result_of_wrap_callable_class<C &> {
120 typedef typename result_of_wrap_callable_class<C>::type &type;
121};
122
123template<typename F, bool TestCallability = true> struct cpp0x_result_of_impl;
124
125#else // BOOST_NO_SFINAE_EXPR
126
127template<typename T>
128struct result_of_always_void
129{
130 typedef void type;
131};
132
133template<typename F, typename Enable = void> struct cpp0x_result_of_impl {};
134
135#endif // BOOST_NO_SFINAE_EXPR
136
137template<typename F>
138struct result_of_void_impl
139{
140 typedef void type;
141};
142
143template<typename R>
144struct result_of_void_impl<R (*)(void)>
145{
146 typedef R type;
147};
148
149template<typename R>
150struct result_of_void_impl<R (&)(void)>
151{
152 typedef R type;
153};
154
155// Determine the return type of a function pointer or pointer to member.
156template<typename F, typename FArgs>
157struct result_of_pointer
158 : tr1_result_of_impl<typename remove_cv<F>::type, FArgs, false> { };
159
160template<typename F, typename FArgs>
161struct tr1_result_of_impl<F, FArgs, true>
162{
163 typedef typename F::result_type type;
164};
165
166template<typename FArgs>
167struct is_function_with_no_args : mpl::false_ {};
168
169template<typename F>
170struct is_function_with_no_args<F(void)> : mpl::true_ {};
171
172template<typename F, typename FArgs>
173struct result_of_nested_result : F::template result<FArgs>
174{};
175
176template<typename F, typename FArgs>
177struct tr1_result_of_impl<F, FArgs, false>
178 : mpl::if_<is_function_with_no_args<FArgs>,
179 result_of_void_impl<F>,
180 result_of_nested_result<F, FArgs> >::type
181{};
182
183} // end namespace detail
184
185#define BOOST_PP_ITERATION_PARAMS_1 (3,(0,BOOST_RESULT_OF_NUM_ARGS,<ndnboost/utility/detail/result_of_iterate.hpp>))
186#include BOOST_PP_ITERATE()
187
188#else
189# define BOOST_NO_RESULT_OF 1
190#endif
191
192}
193
194#endif // BOOST_RESULT_OF_HPP