1 // Copyright Troy D. Straszheim 2009
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 //
6 //
7 //  example that shows problems with overloading and automatic conversion.
8 //  if you call one of the below functions from python with bool/int/double,
9 //  you'll see that the overload called is first match, not best match.
10 //  See overload matching in luabind for an example of how to do this better.
11 //
12 //  see this mail:
13 //  http://mail.python.org/pipermail/cplusplus-sig/2009-March/014362.html
14 //
15 //  This test isn't called by the cmake/jamfiles.  For future use.
16 //
17 #include <boost/python/module.hpp>
18 #include <boost/python/def.hpp>
19 #include <complex>
20 #include <boost/python/handle.hpp>
21 #include <boost/python/cast.hpp>
22 #include <boost/python/object.hpp>
23 #include <boost/python/detail/wrap_python.hpp>
24 
25 using boost::python::def;
26 using boost::python::handle;
27 using boost::python::object;
28 using boost::python::borrowed;
29 
takes_bool(bool b)30 std::string takes_bool(bool b) { return "bool"; }
takes_int(int b)31 std::string takes_int(int b) { return "int"; }
takes_double(double b)32 std::string takes_double(double b) { return "double"; }
33 
34 
BOOST_PYTHON_MODULE(overload_resolution)35 BOOST_PYTHON_MODULE(overload_resolution)
36 {
37   def("bid", takes_bool);
38   def("bid", takes_int);
39   def("bid", takes_double);
40 
41   def("dib", takes_double);
42   def("dib", takes_int);
43   def("dib", takes_bool);
44 
45   def("idb", takes_int);
46   def("idb", takes_double);
47   def("idb", takes_bool);
48 
49   def("bdi", takes_bool);
50   def("bdi", takes_double);
51   def("bdi", takes_int);
52 }
53 
54