borrowed.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. // Copyright David Abrahams 2002.
  2. // Distributed under the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #include <boost/python/detail/wrap_python.hpp>
  6. #include <boost/python/borrowed.hpp>
  7. #include <boost/static_assert.hpp>
  8. using namespace boost::python;
  9. template <class T>
  10. void assert_borrowed_ptr(T const&)
  11. {
  12. BOOST_STATIC_ASSERT(boost::python::detail::is_borrowed_ptr<T>::value);
  13. }
  14. template <class T>
  15. void assert_not_borrowed_ptr(T const&)
  16. {
  17. BOOST_STATIC_ASSERT(!boost::python::detail::is_borrowed_ptr<T>::value);
  18. }
  19. int main()
  20. {
  21. assert_borrowed_ptr(borrowed((PyObject*)0));
  22. assert_borrowed_ptr(borrowed((PyTypeObject*)0));
  23. assert_borrowed_ptr((detail::borrowed<PyObject> const*)0);
  24. assert_borrowed_ptr((detail::borrowed<PyObject> volatile*)0);
  25. assert_borrowed_ptr((detail::borrowed<PyObject> const volatile*)0);
  26. assert_not_borrowed_ptr((PyObject*)0);
  27. assert_not_borrowed_ptr(0);
  28. return 0;
  29. }