@@ -197,6 +197,7 @@ namespace api
197197# endif
198198 };
199199
200+
200201 // VC6 and VC7 require this base class in order to generate the
201202 // correct copy constructor for object. We can't define it there
202203 // explicitly or it will complain of ambiguity.
@@ -216,6 +217,47 @@ namespace api
216217 PyObject* m_ptr;
217218 };
218219
220+ template <class T , class U >
221+ struct is_derived_impl
222+ {
223+ static T x;
224+ template <class X >
225+ static X* to_pointer (X const &);
226+
227+ static char test (U const *);
228+ typedef char (&no)[2];
229+ static no test (...);
230+
231+ BOOST_STATIC_CONSTANT (bool , value = sizeof (test(to_pointer(x))) == 1 );
232+ };
233+
234+ template <class T , class U >
235+ struct is_derived
236+ : mpl::bool_<is_derived_impl<T,U>::value>
237+ {};
238+
239+ template <class T >
240+ typename objects::unforward_cref<T>::type do_unforward_cref (T const & x)
241+ {
242+ return x;
243+ }
244+
245+ class object ;
246+
247+ template <class T >
248+ PyObject* object_base_initializer (T const & x)
249+ {
250+ return object_initializer<
251+ BOOST_DEDUCED_TYPENAME unwrap_reference<T>::type
252+ >::get (
253+ api::do_unforward_cref (x)
254+ , is_derived<
255+ BOOST_DEDUCED_TYPENAME objects::unforward_cref<T>::type
256+ , object
257+ >()
258+ );
259+ }
260+
219261 class object : public object_base
220262 {
221263 public:
@@ -225,26 +267,14 @@ namespace api
225267 // explicit conversion from any C++ object to Python
226268 template <class T >
227269 explicit object (T const & x)
228- : object_base(
229- object_initializer<
230- BOOST_DEDUCED_TYPENAME unwrap_reference<T>::type
231- >::get(
232- object::do_unforward (x)
233- , is_convertible<T*, object const *>()
234- ))
270+ : object_base(object_base_initializer(x))
235271 {
236272 }
237273
238274 // Throw error_already_set() if the handle is null.
239275 BOOST_PYTHON_DECL explicit object (handle<> const &);
240276 private:
241277
242- template <class T >
243- typename objects::unforward_cref<T>::type do_unforward (T const & x)
244- {
245- return x;
246- }
247-
248278 public: // implementation detail -- for internal use only
249279 explicit object (detail::borrowed_reference);
250280 explicit object (detail::new_reference);
0 commit comments