2
0
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:
Haoyu Bai
2009-07-09 17:45:26 +00:00
parent ff0e58d30d
commit 3a75666f22
2 changed files with 14 additions and 1 deletions

View File

@@ -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))
{}

View File

@@ -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