mirror of
https://github.com/pybind/pybind11.git
synced 2025-01-19 09:25:51 +00:00
Merge pull request #429 from jagerman/accessor-bool-operator
Re-add accessor bool operator
This commit is contained in:
commit
68a9989298
@ -206,6 +206,18 @@ public:
|
||||
void operator=(handle value) && { Policy::set(obj, key, value); }
|
||||
void operator=(handle value) & { get_cache() = object(value, true); }
|
||||
|
||||
template <typename T = Policy>
|
||||
PYBIND11_DEPRECATED("Use of obj.attr(...) as bool is deprecated in favor of pybind11::hasattr(obj, ...)")
|
||||
operator enable_if_t<std::is_same<T, accessor_policies::str_attr>::value ||
|
||||
std::is_same<T, accessor_policies::obj_attr>::value, bool>() const {
|
||||
return hasattr(obj, key);
|
||||
}
|
||||
template <typename T = Policy>
|
||||
PYBIND11_DEPRECATED("Use of obj[key] as bool is deprecated in favor of obj.contains(key)")
|
||||
operator enable_if_t<std::is_same<T, accessor_policies::generic_item>::value, bool>() const {
|
||||
return obj.contains(key);
|
||||
}
|
||||
|
||||
operator object() const { return get_cache(); }
|
||||
PyObject *ptr() const { return get_cache().ptr(); }
|
||||
template <typename T> T cast() const { return get_cache().template cast<T>(); }
|
||||
|
Loading…
Reference in New Issue
Block a user