@@ -70,6 +70,9 @@ struct module_local { const bool value; constexpr module_local(bool v = true) :
7070// / Annotation to mark enums as an arithmetic type
7171struct arithmetic { };
7272
73+ // / Mark a function for addition at the beginning of the existing overload chain instead of the end
74+ struct prepend { };
75+
7376/* * \rst
7477 A call policy which places one or more guard variables (``Ts...``) around the function call.
7578
@@ -134,7 +137,8 @@ struct argument_record {
134137struct function_record {
135138 function_record ()
136139 : is_constructor(false ), is_new_style_constructor(false ), is_stateless(false ),
137- is_operator (false ), has_args(false ), has_kwargs(false ), is_method(false ) { }
140+ is_operator (false ), has_args(false ), has_kwargs(false ), is_method(false ),
141+ is_prepended(false ) { }
138142
139143 // / Function name
140144 char *name = nullptr ; /* why no C++ strings? They generate heavier code.. */
@@ -181,6 +185,9 @@ struct function_record {
181185 // / True if this is a method
182186 bool is_method : 1 ;
183187
188+ // / True if this function is to be inserted at the beginning of the overload resolution chain
189+ bool is_prepended : 1 ;
190+
184191 // / Number of arguments (including py::args and/or py::kwargs, if present)
185192 std::uint16_t nargs;
186193
@@ -427,6 +434,11 @@ struct process_attribute<module_local> : process_attribute_default<module_local>
427434 static void init (const module_local &l, type_record *r) { r->module_local = l.value ; }
428435};
429436
437+ // / Process an 'prepend' attribute, putting this at the top of the overload chain
438+ template <> struct process_attribute <prepend> : process_attribute_default<prepend> {
439+ static void init (const prepend &, function_record *r) { r->is_prepended = true ; }
440+ };
441+
430442// / Process an 'arithmetic' attribute for enums (does nothing here)
431443template <>
432444struct process_attribute <arithmetic> : process_attribute_default<arithmetic> {};
0 commit comments