select_holder.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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/object/class_metadata.hpp>
  6. #include <boost/python/has_back_reference.hpp>
  7. #include <boost/python/detail/not_specified.hpp>
  8. #include <boost/static_assert.hpp>
  9. #include <boost/python/detail/type_traits.hpp>
  10. #include <boost/function/function0.hpp>
  11. #include <boost/mpl/bool.hpp>
  12. #include <memory>
  13. struct BR {};
  14. struct Base {};
  15. struct Derived : Base {};
  16. namespace boost { namespace python
  17. {
  18. // specialization
  19. template <>
  20. struct has_back_reference<BR>
  21. : mpl::true_
  22. {
  23. };
  24. }} // namespace boost::python
  25. template <class T, class U>
  26. void assert_same(U* = 0, T* = 0)
  27. {
  28. BOOST_STATIC_ASSERT((boost::python::detail::is_same<T,U>::value));
  29. }
  30. template <class T, class Held, class Holder>
  31. void assert_holder(T* = 0, Held* = 0, Holder* = 0)
  32. {
  33. using namespace boost::python::detail;
  34. using namespace boost::python::objects;
  35. typedef typename class_metadata<
  36. T,Held,not_specified,not_specified
  37. >::holder h;
  38. assert_same<Holder>(
  39. (h*)0
  40. );
  41. }
  42. int test_main(int, char * [])
  43. {
  44. using namespace boost::python::detail;
  45. using namespace boost::python::objects;
  46. assert_holder<Base,not_specified,value_holder<Base> >();
  47. assert_holder<BR,not_specified,value_holder_back_reference<BR,BR> >();
  48. assert_holder<Base,Base,value_holder_back_reference<Base,Base> >();
  49. assert_holder<BR,BR,value_holder_back_reference<BR,BR> >();
  50. assert_holder<Base,Derived
  51. ,value_holder_back_reference<Base,Derived> >();
  52. assert_holder<Base,std::auto_ptr<Base>
  53. ,pointer_holder<std::auto_ptr<Base>,Base> >();
  54. assert_holder<Base,std::auto_ptr<Derived>
  55. ,pointer_holder_back_reference<std::auto_ptr<Derived>,Base> >();
  56. assert_holder<BR,std::auto_ptr<BR>
  57. ,pointer_holder_back_reference<std::auto_ptr<BR>,BR> > ();
  58. return 0;
  59. }