14
14
15
15
NAMESPACE_BEGIN (pybind11)
16
16
17
- template <typename T> struct arg_t;
18
-
19
- // / Annotation for keyword arguments
20
- struct arg {
21
- constexpr explicit arg (const char *name) : name(name) { }
22
-
23
- template <typename T>
24
- constexpr arg_t <T> operator =(const T &value) const { return {name, value}; }
25
- template <typename T, size_t N>
26
- constexpr arg_t <const T *> operator =(T const (&value)[N]) const {
27
- return operator =((const T *) value);
28
- }
29
-
30
- const char *name;
31
- };
32
-
33
- // / Annotation for keyword arguments with default values
34
- template <typename T> struct arg_t : public arg {
35
- constexpr arg_t (const char *name, const T &value, const char *descr = nullptr )
36
- : arg(name), value(value), descr(descr) { }
37
- T value;
38
- const char *descr;
39
- };
40
-
41
- inline namespace literals {
42
- // / String literal version of arg
43
- constexpr arg operator " " _a(const char *name, size_t ) { return arg (name); }
44
- }
45
-
46
17
// / Annotation for methods
47
18
struct is_method { handle class_; is_method (const handle &c) : class_ (c) { } };
48
19
@@ -238,21 +209,14 @@ template <> struct process_attribute<arg> : process_attribute_default<arg> {
238
209
};
239
210
240
211
// / Process a keyword argument attribute (*with* a default value)
241
- template <typename T>
242
- struct process_attribute <arg_t <T>> : process_attribute_default<arg_t <T>> {
243
- static void init (const arg_t <T> &a, function_record *r) {
212
+ template <> struct process_attribute <arg_v> : process_attribute_default<arg_v> {
213
+ static void init (const arg_v &a, function_record *r) {
244
214
if (r->class_ && r->args .empty ())
245
215
r->args .emplace_back (" self" , nullptr , handle ());
246
216
247
- /* Convert keyword value into a Python object */
248
- object o = object (detail::type_caster<typename detail::intrinsic_type<T>::type>::cast (
249
- a.value , return_value_policy::automatic, handle ()), false );
250
-
251
- if (!o) {
217
+ if (!a.value ) {
252
218
#if !defined(NDEBUG)
253
- std::string descr (typeid (T).name ());
254
- detail::clean_type_id (descr);
255
- descr = " '" + std::string (a.name ) + " : " + descr + " '" ;
219
+ auto descr = " '" + std::string (a.name ) + " : " + a.type + " '" ;
256
220
if (r->class_ ) {
257
221
if (r->name )
258
222
descr += " in method '" + (std::string) r->class_ .str () + " ." + (std::string) r->name + " '" ;
@@ -269,7 +233,7 @@ struct process_attribute<arg_t<T>> : process_attribute_default<arg_t<T>> {
269
233
" Compile in debug mode for more information." );
270
234
#endif
271
235
}
272
- r->args .emplace_back (a.name , a.descr , o. release ());
236
+ r->args .emplace_back (a.name , a.descr , a. value . inc_ref ());
273
237
}
274
238
};
275
239
@@ -301,9 +265,6 @@ template <int Nurse, int Patient> struct process_attribute<keep_alive<Nurse, Pat
301
265
static void postcall (handle args, handle ret) { keep_alive_impl (Nurse, Patient, args, ret); }
302
266
};
303
267
304
- // / Ignore that a variable is unused in compiler warnings
305
- inline void ignore_unused (const int *) { }
306
-
307
268
// / Recursively iterate over variadic template arguments
308
269
template <typename ... Args> struct process_attributes {
309
270
static void init (const Args&... args, function_record *r) {
@@ -324,11 +285,6 @@ template <typename... Args> struct process_attributes {
324
285
}
325
286
};
326
287
327
- // / Compile-time integer sum
328
- constexpr size_t constexpr_sum () { return 0 ; }
329
- template <typename T, typename ... Ts>
330
- constexpr size_t constexpr_sum (T n, Ts... ns) { return n + constexpr_sum (ns...); }
331
-
332
288
// / Check the number of named arguments at compile time
333
289
template <typename ... Extra,
334
290
size_t named = constexpr_sum(std::is_base_of<arg, Extra>::value...),
0 commit comments