blob: b98fc8ad43a1bb4b8fea8914e36bae01fa28b17a [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
Jeff Thompson3d613fd2013-10-15 15:39:04 -07009#ifndef NDNBOOST_RESULT_OF_HPP
10#define NDNBOOST_RESULT_OF_HPP
Jeff Thompsona28eed82013-08-22 16:21:10 -070011
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
Jeff Thompson3d613fd2013-10-15 15:39:04 -070035#ifndef NDNBOOST_RESULT_OF_NUM_ARGS
36# define NDNBOOST_RESULT_OF_NUM_ARGS 16
Jeff Thompsona28eed82013-08-22 16:21:10 -070037#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>.
Jeff Thompson3d613fd2013-10-15 15:39:04 -070041// The user can force the choice by defining either NDNBOOST_RESULT_OF_USE_DECLTYPE or
42// NDNBOOST_RESULT_OF_USE_TR1, but not both!
43#if defined(NDNBOOST_RESULT_OF_USE_DECLTYPE) && defined(NDNBOOST_RESULT_OF_USE_TR1)
44# error Both NDNBOOST_RESULT_OF_USE_DECLTYPE and NDNBOOST_RESULT_OF_USE_TR1 cannot be defined at the same time.
Jeff Thompsona28eed82013-08-22 16:21:10 -070045#endif
46
Jeff Thompson3d613fd2013-10-15 15:39:04 -070047#ifndef NDNBOOST_RESULT_OF_USE_TR1
48# ifndef NDNBOOST_RESULT_OF_USE_DECLTYPE
49# ifndef NDNBOOST_NO_CXX11_DECLTYPE_N3276 // this implies !defined(NDNBOOST_NO_CXX11_DECLTYPE)
50# define NDNBOOST_RESULT_OF_USE_DECLTYPE
Jeff Thompsona28eed82013-08-22 16:21:10 -070051# else
Jeff Thompson3d613fd2013-10-15 15:39:04 -070052# define NDNBOOST_RESULT_OF_USE_TR1
Jeff Thompsona28eed82013-08-22 16:21:10 -070053# 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
Jeff Thompson3d613fd2013-10-15 15:39:04 -070062#if !defined(NDNBOOST_NO_SFINAE) && !defined(NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
Jeff Thompsona28eed82013-08-22 16:21:10 -070063namespace detail {
64
Jeff Thompson3d613fd2013-10-15 15:39:04 -070065NDNBOOST_MPL_HAS_XXX_TRAIT_DEF(result_type)
Jeff Thompsona28eed82013-08-22 16:21:10 -070066
67template<typename F, typename FArgs, bool HasResultType> struct tr1_result_of_impl;
68
Jeff Thompson3d613fd2013-10-15 15:39:04 -070069#ifdef NDNBOOST_NO_SFINAE_EXPR
Jeff Thompsona28eed82013-08-22 16:21:10 -070070
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.
Jeff Thompson3d613fd2013-10-15 15:39:04 -070074#if NDNBOOST_MSVC
Jeff Thompsona28eed82013-08-22 16:21:10 -070075# 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
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700125#else // NDNBOOST_NO_SFINAE_EXPR
Jeff Thompsona28eed82013-08-22 16:21:10 -0700126
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
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700135#endif // NDNBOOST_NO_SFINAE_EXPR
Jeff Thompsona28eed82013-08-22 16:21:10 -0700136
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
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700185#define NDNBOOST_PP_ITERATION_PARAMS_1 (3,(0,NDNBOOST_RESULT_OF_NUM_ARGS,<ndnboost/utility/detail/result_of_iterate.hpp>))
186#include NDNBOOST_PP_ITERATE()
Jeff Thompsona28eed82013-08-22 16:21:10 -0700187
188#else
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700189# define NDNBOOST_NO_RESULT_OF 1
Jeff Thompsona28eed82013-08-22 16:21:10 -0700190#endif
191
192}
193
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700194#endif // NDNBOOST_RESULT_OF_HPP