Swap order of attr_with_type_hint implementation in cast.h (so that the const char * overload appears first).

This commit is contained in:
Ralf W. Grosse-Kunstleve 2024-12-20 12:30:27 -08:00
parent a6ffbe35c4
commit cd4f771b12
No known key found for this signature in database

View File

@ -1371,6 +1371,22 @@ using py_str = str;
// Declared in pytypes.h: // Declared in pytypes.h:
// Written here so make_caster<T> can be used // Written here so make_caster<T> can be used
template <typename D>
template <typename T>
str_attr_accessor object_api<D>::attr_with_type_hint(const char *key) const {
#if !defined(__cpp_inline_variables)
static_assert(!std::is_same<T, T>::value,
"C++17 feature __cpp_inline_variables not available: "
"https://en.cppreference.com/w/cpp/language/static#Static_data_members");
#endif
object ann = annotations();
if (ann.contains(key)) {
throw std::runtime_error("__annotations__[\"" + std::string(key) + "\"] was set already.");
}
ann[key] = make_caster<T>::name.text;
return {derived(), key};
}
template <typename D> template <typename D>
template <typename T> template <typename T>
obj_attr_accessor object_api<D>::attr_with_type_hint(handle key) const { obj_attr_accessor object_api<D>::attr_with_type_hint(handle key) const {
@ -1389,22 +1405,6 @@ obj_attr_accessor object_api<D>::attr_with_type_hint(handle key) const {
return {derived(), reinterpreted_key}; return {derived(), reinterpreted_key};
} }
template <typename D>
template <typename T>
str_attr_accessor object_api<D>::attr_with_type_hint(const char *key) const {
#if !defined(__cpp_inline_variables)
static_assert(!std::is_same<T, T>::value,
"C++17 feature __cpp_inline_variables not available: "
"https://en.cppreference.com/w/cpp/language/static#Static_data_members");
#endif
object ann = annotations();
if (ann.contains(key)) {
throw std::runtime_error("__annotations__[\"" + std::string(key) + "\"] was set already.");
}
ann[key] = make_caster<T>::name.text;
return {derived(), key};
}
// Placeholder type for the unneeded (and dead code) static variable in the // Placeholder type for the unneeded (and dead code) static variable in the
// PYBIND11_OVERRIDE_OVERRIDE macro // PYBIND11_OVERRIDE_OVERRIDE macro
struct override_unused {}; struct override_unused {};