From cc39b2f37fafd6b9949f6bc6210880710e5030bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Sat, 26 Dec 2015 19:01:28 +0100 Subject: [PATCH] Add const modifier to handle::cast. --- docs/reference.rst | 2 +- include/pybind11/cast.h | 4 ++-- include/pybind11/pytypes.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/reference.rst b/docs/reference.rst index 16d2a8d14..bf7a8e276 100644 --- a/docs/reference.rst +++ b/docs/reference.rst @@ -118,7 +118,7 @@ Without reference counting Return a string representation of the object. This is analogous to the ``str()`` function in Python. -.. function:: template T handle::cast() +.. function:: template T handle::cast() const Attempt to cast the Python object into the given C++ type. A :class:`cast_error` will be throw upon failure. diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 456af7ebb..ecbf3843e 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -594,8 +594,8 @@ template inline object cast(const T &value, return_value_policy pol return object(detail::type_caster::type>::cast(value, policy, parent), false); } -template inline T handle::cast() { return pybind11::cast(m_ptr); } -template <> inline void handle::cast() { return; } +template inline T handle::cast() const { return pybind11::cast(m_ptr); } +template <> inline void handle::cast() const { return; } template inline object handle::call(Args&&... args_) { const size_t size = sizeof...(Args); diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index 01776d7eb..2a9c7fa33 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -42,7 +42,7 @@ public: inline detail::accessor attr(handle key); inline detail::accessor attr(const char *key); inline pybind11::str str() const; - template T cast(); + template T cast() const; template object call(Args&&... args_); operator bool() const { return m_ptr != nullptr; } bool check() const { return m_ptr != nullptr; }