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 11 using namespace boost::python; 12 13 typedef test_class<> X; 14 x_value(X const & x)15int x_value(X const& x) 16 { 17 return x.value(); 18 } 19 make_x(int n)20X make_x(int n) { return X(n); } 21 22 23 // foo/bar -- a regression for a vc7 bug workaround 24 struct bar {}; 25 struct foo 26 { ~foofoo27 virtual ~foo() {}; // silence compiler warnings 28 virtual void f() = 0; operator barfoo29 operator bar() const { return bar(); } 30 }; 31 BOOST_PYTHON_MODULE(implicit_ext)32BOOST_PYTHON_MODULE(implicit_ext) 33 { 34 implicitly_convertible<foo,bar>(); 35 implicitly_convertible<int,X>(); 36 37 def("x_value", x_value); 38 def("make_x", make_x); 39 40 class_<X>("X", init<int>()) 41 .def("value", &X::value) 42 .def("set", &X::set) 43 ; 44 45 implicitly_convertible<X,int>(); 46 } 47 48 #include "module_tail.cpp" 49