@@ -74,6 +74,9 @@ struct module_local { const bool value; constexpr module_local(bool v = true) :
7474// / Annotation to mark enums as an arithmetic type
7575struct arithmetic { };
7676
77+ // / Mark a function for addition at the beginning of the existing overload chain instead of the end
78+ struct prepend { };
79+
7780/* * \rst
7881 A call policy which places one or more guard variables (``Ts...``) around the function call.
7982
@@ -138,8 +141,8 @@ struct argument_record {
138141struct function_record {
139142 function_record ()
140143 : is_constructor(false ), is_new_style_constructor(false ), is_stateless(false ),
141- is_operator (false ), is_method(false ),
142- has_args (false ), has_kwargs (false ), has_kw_only_args (false ) { }
144+ is_operator (false ), is_method(false ), has_args( false ),
145+ has_kwargs (false ), has_kw_only_args (false ), prepend (false ) { }
143146
144147 // / Function name
145148 char *name = nullptr ; /* why no C++ strings? They generate heavier code.. */
@@ -189,6 +192,9 @@ struct function_record {
189192 // / True once a 'py::kw_only' is encountered (any following args are keyword-only)
190193 bool has_kw_only_args : 1 ;
191194
195+ // / True if this function is to be inserted at the beginning of the overload resolution chain
196+ bool prepend : 1 ;
197+
192198 // / Number of arguments (including py::args and/or py::kwargs, if present)
193199 std::uint16_t nargs;
194200
@@ -477,6 +483,12 @@ struct process_attribute<module_local> : process_attribute_default<module_local>
477483 static void init (const module_local &l, type_record *r) { r->module_local = l.value ; }
478484};
479485
486+ // / Process a 'prepend' attribute, putting this at the beginning of the overload chain
487+ template <>
488+ struct process_attribute <prepend> : process_attribute_default<prepend> {
489+ static void init (const prepend &, function_record *r) { r->prepend = true ; }
490+ };
491+
480492// / Process an 'arithmetic' attribute for enums (does nothing here)
481493template <>
482494struct process_attribute <arithmetic> : process_attribute_default<arithmetic> {};
0 commit comments