implicit.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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/class.hpp>
  6. #include <boost/python/implicit.hpp>
  7. #include <boost/python/module.hpp>
  8. #include <boost/python/def.hpp>
  9. #include "test_class.hpp"
  10. using namespace boost::python;
  11. typedef test_class<> X;
  12. int x_value(X const& x)
  13. {
  14. return x.value();
  15. }
  16. X make_x(int n) { return X(n); }
  17. // foo/bar -- a regression for a vc7 bug workaround
  18. struct bar {};
  19. struct foo
  20. {
  21. virtual ~foo() {}; // silence compiler warnings
  22. virtual void f() = 0;
  23. operator bar() const { return bar(); }
  24. };
  25. BOOST_PYTHON_MODULE(implicit_ext)
  26. {
  27. implicitly_convertible<foo,bar>();
  28. implicitly_convertible<int,X>();
  29. def("x_value", x_value);
  30. def("make_x", make_x);
  31. class_<X>("X", init<int>())
  32. .def("value", &X::value)
  33. .def("set", &X::set)
  34. ;
  35. implicitly_convertible<X,int>();
  36. }
  37. #include "module_tail.cpp"