First public contribution.
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 #ifndef IMPLICIT_DWA2002326_HPP
6 # define IMPLICIT_DWA2002326_HPP
8 # include <boost/python/converter/rvalue_from_python_data.hpp>
9 # include <boost/python/converter/registrations.hpp>
10 # include <boost/python/converter/registered.hpp>
12 # include <boost/python/extract.hpp>
14 namespace boost { namespace python { namespace converter {
16 template <class Source, class Target>
19 static void* convertible(PyObject* obj)
21 // Find a converter which can produce a Source instance from
22 // obj. The user has told us that Source can be converted to
23 // Target, and instantiating construct() below, ensures that
25 return implicit_rvalue_convertible_from_python(obj, registered<Source>::converters)
29 static void construct(PyObject* obj, rvalue_from_python_stage1_data* data)
31 void* storage = ((rvalue_from_python_storage<Target>*)data)->storage.bytes;
33 arg_from_python<Source> get_source(obj);
34 bool convertible = get_source.convertible();
35 BOOST_ASSERT(convertible);
37 new (storage) Target(get_source());
39 // record successful construction
40 data->convertible = storage;
44 }}} // namespace boost::python::converter
46 #endif // IMPLICIT_DWA2002326_HPP