|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r54836 - in sandbox-branches/bhy/py3k: boost/python libs/python/src
From: divinekid_at_[hidden]
Date: 2009-07-09 13:45:27
Author: bhy
Date: 2009-07-09 13:45:26 EDT (Thu, 09 Jul 2009)
New Revision: 54836
URL: http://svn.boost.org/trac/boost/changeset/54836
Log:
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
Text files modified:
sandbox-branches/bhy/py3k/boost/python/object_core.hpp | 13 +++++++++++++
sandbox-branches/bhy/py3k/libs/python/src/dict.cpp | 2 +-
2 files changed, 14 insertions(+), 1 deletions(-)
Modified: sandbox-branches/bhy/py3k/boost/python/object_core.hpp
==============================================================================
--- sandbox-branches/bhy/py3k/boost/python/object_core.hpp (original)
+++ sandbox-branches/bhy/py3k/boost/python/object_core.hpp 2009-07-09 13:45:26 EDT (Thu, 09 Jul 2009)
@@ -126,6 +126,10 @@
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 @@
}
+
+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))
{}
Modified: sandbox-branches/bhy/py3k/libs/python/src/dict.cpp
==============================================================================
--- sandbox-branches/bhy/py3k/libs/python/src/dict.cpp (original)
+++ sandbox-branches/bhy/py3k/libs/python/src/dict.cpp 2009-07-09 13:45:26 EDT (Thu, 09 Jul 2009)
@@ -84,7 +84,7 @@
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
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk