Chris@16: // Copyright David Abrahams 2002. Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: #ifndef BACK_REFERENCE_DWA2002510_HPP Chris@16: # define BACK_REFERENCE_DWA2002510_HPP Chris@16: Chris@16: # include Chris@16: Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: Chris@16: namespace boost { namespace python { Chris@16: Chris@16: template Chris@16: struct back_reference Chris@16: { Chris@16: private: // types Chris@16: typedef typename detail::dependent::type source_t; Chris@16: public: Chris@16: typedef T type; Chris@16: Chris@16: back_reference(PyObject*, T); Chris@16: source_t const& source() const; Chris@16: T get() const; Chris@16: private: Chris@16: source_t m_source; Chris@16: T m_value; Chris@16: }; Chris@16: Chris@16: # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION Chris@16: template Chris@16: class is_back_reference Chris@16: { Chris@16: public: Chris@16: BOOST_STATIC_CONSTANT(bool, value = false); Chris@16: }; Chris@16: Chris@16: template Chris@16: class is_back_reference > Chris@16: { Chris@16: public: Chris@16: BOOST_STATIC_CONSTANT(bool, value = true); Chris@16: }; Chris@16: Chris@16: # else // no partial specialization Chris@16: Chris@16: }} // namespace boost::python Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { namespace python { Chris@16: Chris@16: namespace detail Chris@16: { Chris@16: typedef char (&yes_back_reference_t)[1]; Chris@16: typedef char (&no_back_reference_t)[2]; Chris@16: Chris@16: no_back_reference_t is_back_reference_test(...); Chris@16: Chris@16: template Chris@16: yes_back_reference_t is_back_reference_test(boost::type< back_reference >); Chris@16: } Chris@16: Chris@16: template Chris@16: class is_back_reference Chris@16: { Chris@16: public: Chris@16: BOOST_STATIC_CONSTANT( Chris@16: bool, value = ( Chris@16: sizeof(detail::is_back_reference_test(boost::type())) Chris@16: == sizeof(detail::yes_back_reference_t))); Chris@16: }; Chris@16: Chris@16: # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION Chris@16: Chris@16: // Chris@16: // implementations Chris@16: // Chris@16: template Chris@16: back_reference::back_reference(PyObject* p, T x) Chris@16: : m_source(detail::borrowed_reference(p)) Chris@16: , m_value(x) Chris@16: { Chris@16: } Chris@16: Chris@16: template Chris@16: typename back_reference::source_t const& back_reference::source() const Chris@16: { Chris@16: return m_source; Chris@16: } Chris@16: Chris@16: template Chris@16: T back_reference::get() const Chris@16: { Chris@16: return m_value; Chris@16: } Chris@16: Chris@16: }} // namespace boost::python Chris@16: Chris@16: #endif // BACK_REFERENCE_DWA2002510_HPP