Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/python/test/implicit.cpp @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

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