]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/contract/override.hpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / boost / contract / override.hpp
1
2 #ifndef BOOST_CONTRACT_OVERRIDE_HPP_
3 #define BOOST_CONTRACT_OVERRIDE_HPP_
4
5 // Copyright (C) 2008-2018 Lorenzo Caminiti
6 // Distributed under the Boost Software License, Version 1.0 (see accompanying
7 // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
8 // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
9
10 /** @file
11 Handle public function overrides (for subcontracting).
12 */
13
14 // IMPORTANT: Included by contract_macro.hpp so must #if-guard all its includes.
15 #include <boost/contract/core/config.hpp>
16 #include <boost/preprocessor/cat.hpp>
17 #include <boost/preprocessor/config/config.hpp>
18
19 #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
20 /**
21 Declare an override type with an arbitrary name.
22
23 Declare the override type to pass as an explicit template parameter to
24 @RefFunc{boost::contract::public_function} for public function overrides.
25
26 @see @RefSect{advanced.named_overrides, Named Overrides}
27
28 @param type_name Name of the override type this macro will declare.
29 (This is not a variadic macro parameter but it should
30 never contain commas because it is an identifier.)
31 @param func_name Function name of the public function override.
32 This macro is called just once even if the function name
33 is overloaded (the same override type is used for all
34 overloaded functions with the same name, see
35 @RefSect{advanced.function_overloads,
36 Function Overloads}).
37 (This is not a variadic macro parameter but it should
38 never contain commas because it is an identifier.)
39 */
40 #define BOOST_CONTRACT_NAMED_OVERRIDE(type_name, func_name)
41 #elif !defined(BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS)
42 #include <boost/contract/core/virtual.hpp>
43 #include <boost/contract/detail/type_traits/mirror.hpp>
44 #include <boost/contract/detail/tvariadic.hpp>
45 #include <boost/contract/detail/none.hpp>
46 #include <boost/contract/detail/name.hpp>
47
48 /* PRIVATE */
49
50 #define BOOST_CONTRACT_OVERRIDE_CALL_BASE_(z, arity, arity_compl, \
51 func_name) \
52 template< \
53 class BOOST_CONTRACT_DETAIL_NAME1(B), \
54 class BOOST_CONTRACT_DETAIL_NAME1(C) \
55 BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(arity) \
56 BOOST_CONTRACT_DETAIL_TVARIADIC_TPARAMS_Z(z, arity, \
57 BOOST_CONTRACT_DETAIL_NAME1(Args)) \
58 > \
59 static void BOOST_CONTRACT_DETAIL_NAME1(call_base)( \
60 boost::contract::virtual_* BOOST_CONTRACT_DETAIL_NAME1(v), \
61 BOOST_CONTRACT_DETAIL_NAME1(C)* BOOST_CONTRACT_DETAIL_NAME1(obj) \
62 BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(arity) \
63 BOOST_CONTRACT_DETAIL_TVARIADIC_FPARAMS_Z(z, arity, \
64 BOOST_CONTRACT_DETAIL_NAME1(Args), \
65 &, \
66 BOOST_CONTRACT_DETAIL_NAME1(args) \
67 ) \
68 BOOST_CONTRACT_DETAIL_NO_TVARIADIC_COMMA(arity_compl) \
69 BOOST_CONTRACT_DETAIL_NO_TVARIADIC_ENUM_Z(z, arity_compl, \
70 boost::contract::detail::none&) \
71 ) { \
72 BOOST_CONTRACT_DETAIL_NAME1(obj)-> \
73 BOOST_CONTRACT_DETAIL_NAME1(B)::func_name( \
74 BOOST_CONTRACT_DETAIL_TVARIADIC_ARGS_Z(z, arity, \
75 BOOST_CONTRACT_DETAIL_NAME1(args)) \
76 BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(arity) \
77 BOOST_CONTRACT_DETAIL_NAME1(v) \
78 ); \
79 }
80
81 #if BOOST_CONTRACT_DETAIL_TVARIADIC
82 #define BOOST_CONTRACT_OVERRIDE_CALL_BASE_DECL_(func_name) \
83 BOOST_CONTRACT_OVERRIDE_CALL_BASE_(1, ~, ~, func_name)
84 #else
85 #include <boost/preprocessor/repetition/repeat.hpp>
86 #include <boost/preprocessor/arithmetic/inc.hpp>
87 #include <boost/preprocessor/arithmetic/sub.hpp>
88
89 #define BOOST_CONTRACT_OVERRIDE_CALL_BASE_DECL_(func_name) \
90 BOOST_PP_REPEAT(BOOST_PP_INC(BOOST_CONTRACT_MAX_ARGS), \
91 BOOST_CONTRACT_OVERRIDE_CALL_BASE_ARITY_, func_name) \
92
93 #define BOOST_CONTRACT_OVERRIDE_CALL_BASE_ARITY_(z, arity, func_name) \
94 BOOST_CONTRACT_OVERRIDE_CALL_BASE_(z, arity, \
95 BOOST_PP_SUB(BOOST_CONTRACT_MAX_ARGS, arity), func_name)
96 #endif
97
98 /* PUBLIC */
99
100 #define BOOST_CONTRACT_NAMED_OVERRIDE(type_name, func_name) \
101 struct type_name { \
102 BOOST_CONTRACT_DETAIL_MIRROR_HAS_MEMBER_FUNCTION( \
103 BOOST_CONTRACT_DETAIL_NAME1(has_member_function), \
104 func_name \
105 ) \
106 BOOST_CONTRACT_OVERRIDE_CALL_BASE_DECL_(func_name) \
107 };
108 #else
109 #define BOOST_CONTRACT_NAMED_OVERRIDE(type_name, func_name) \
110 struct type_name {}; /* empty (not used), just to compile */
111 #endif
112
113 /* PUBLIC */
114
115 /**
116 Declare an override type named <c>override_<i>func_name</i></c>.
117
118 Declare the override type to pass as an explicit template parameter to
119 @RefFunc{boost::contract::public_function} for public function overrides.
120
121 @see @RefSect{tutorial.public_function_overrides__subcontracting_,
122 Public Function Overrides}
123
124 @param func_name Function name of the public function override.
125 This macro is called just once even if the function name is
126 overloaded (the same override type is used for all
127 overloaded functions with the same name, see
128 @RefSect{advanced.function_overloads, Function Overloads}).
129 (This is not a variadic macro parameter but it should never
130 contain any comma because it is an identifier.)
131 */
132 #define BOOST_CONTRACT_OVERRIDE(func_name) \
133 BOOST_CONTRACT_NAMED_OVERRIDE(BOOST_PP_CAT(override_, func_name), func_name)
134
135 #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
136 /**
137 Declare multiple override types at once naming them <c>override_...</c> (for
138 convenience).
139
140 This variadic macro is provided for convenience only,
141 <c>BOOST_CONTRACT_OVERRIDES(f_1, f_2, ..., f_n)</c> expands to code
142 equivalent to:
143
144 @code
145 BOOST_CONTRACT_OVERRIDE(f_1)
146 BOOST_CONTRACT_OVERRIDE(f_2)
147 ...
148 BOOST_CONTRACT_OVERRIDE(f_n)
149 @endcode
150
151 On compilers that do not support variadic macros,
152 the override types can be equivalently programmed one-by-one calling
153 @RefMacro{BOOST_CONTRACT_OVERRIDE} for each function name as shown above.
154
155 @see @RefSect{tutorial.public_function_overrides__subcontracting_,
156 Public Function Overrides}
157
158 @param ... A comma separated list of one or more function names of public
159 function overrides.
160 (Each function name should never contain commas because it is an
161 identifier.)
162 */
163 #define BOOST_CONTRACT_OVERRIDES(...)
164 #elif BOOST_PP_VARIADICS
165 #include <boost/preprocessor/seq/for_each.hpp>
166 #include <boost/preprocessor/variadic/to_seq.hpp>
167
168 /* PRIVATE */
169
170 #define BOOST_CONTRACT_OVERRIDES_SEQ_(r, unused, func_name) \
171 BOOST_CONTRACT_OVERRIDE(func_name)
172
173 /* PUBLIC */
174
175 #define BOOST_CONTRACT_OVERRIDES(...) \
176 BOOST_PP_SEQ_FOR_EACH(BOOST_CONTRACT_OVERRIDES_SEQ_, ~, \
177 BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__))
178 #else
179 #define BOOST_CONTRACT_OVERRIDES \
180 BOOST_CONTRACT_ERROR_macro_OVERRIDES_requires_variadic_macros_otherwise_manually_repeat_OVERRIDE_macro
181 #endif
182
183 #endif // #include guard
184