1 [section boost/python/implicit.hpp]
3 `implicitly_convertible` allows Boost.Python to implicitly take advantage of a C++ implicit or explicit conversion when matching Python objects to C++ argument types.
5 [section Function template `implicit_convertible`]
7 template <class Source, class Target>
8 void implicitly_convertible();
11 [[Parameter][Description]]
12 [[Source][The source type of the implicit conversion]]
13 [[Target][The target type of the implicit conversion]]
16 [[Requires][The declaration `Target t(s);`, where s is of type Source, is valid.]]
17 [[Effects][registers an rvalue `from_python` converter to Target which can succeed for any `PyObject* p` iff there exists any registered converter which can produce Source rvalues]]
18 [[Rationale][C++ users expect to be able to take advantage of the same sort of interoperability in Python as they do in C++.]]
24 #include <boost/python/class.hpp>
25 #include <boost/python/implicit.hpp>
26 #include <boost/python/module.hpp>
28 using namespace boost::python;
33 operator int() const { return v; }
37 int x_value(X const& x)
42 X make_x(int n) { return X(n); }
44 BOOST_PYTHON_MODULE(implicit_ext)
46 def("x_value", x_value);
47 def("make_x", make_x);
53 implicitly_convertible<X,int>();
54 implicitly_convertible<int,X>();
59 >>> from implicit_ext import *