mirror of
https://github.com/boostorg/python.git
synced 2026-01-23 17:52:17 +00:00
introduce object.contains(), a wrapper of Python 'in' operator. And reimplement dict.has_key by call object.contains(). Because dict.has_key is removed in py3k
[SVN r54836]
This commit is contained in:
@@ -126,6 +126,10 @@ namespace api
|
||||
const_object_objattribute attr(object const&) const;
|
||||
object_objattribute attr(object const&);
|
||||
|
||||
// Wrap 'in' operator (aka. __contains__)
|
||||
template <class T>
|
||||
object contains(T const& key) const;
|
||||
|
||||
// item access
|
||||
//
|
||||
const_object_item operator[](object_cref) const;
|
||||
@@ -483,6 +487,15 @@ object api::object_operators<U>::operator()(detail::args_proxy const &args,
|
||||
|
||||
}
|
||||
|
||||
|
||||
template <typename U>
|
||||
template <class T>
|
||||
object api::object_operators<U>::contains(T const& key) const
|
||||
{
|
||||
return this->attr("__contains__")(object(key));
|
||||
}
|
||||
|
||||
|
||||
inline object::object()
|
||||
: object_base(python::incref(Py_None))
|
||||
{}
|
||||
|
||||
@@ -84,7 +84,7 @@ object dict_base::get(object_cref k, object_cref d) const
|
||||
|
||||
bool dict_base::has_key(object_cref k) const
|
||||
{
|
||||
return extract<bool>(this->attr("has_key")(k));
|
||||
return extract<bool>(this->contains(k));
|
||||
}
|
||||
|
||||
list dict_base::items() const
|
||||
|
||||
Reference in New Issue
Block a user