15 typedef typename pair_type::first_type T1;
16 typedef typename pair_type::second_type T2;
18 static PyObject* convert(
const pair_type& pair) {
19 return boost::python::incref(
20 boost::python::make_tuple(pair.first, pair.second).ptr());
23 static void* convertible(PyObject* obj) {
24 if (!PyTuple_CheckExact(obj))
return 0;
25 if (PyTuple_Size(obj) != 2)
return 0;
27 boost::python::tuple tuple(boost::python::borrowed(obj));
28 boost::python::extract<T1> elt1(tuple[0]);
29 if (!elt1.check())
return 0;
30 boost::python::extract<T2> elt2(tuple[1]);
31 if (!elt2.check())
return 0;
36 static void construct(
38 boost::python::converter::rvalue_from_python_stage1_data* memory) {
39 boost::python::tuple tuple(boost::python::borrowed(obj));
42 boost::python::converter::rvalue_from_python_storage<pair_type>*
>(
43 reinterpret_cast<void*
>(memory))
45 new (storage) pair_type(boost::python::extract<T1>(tuple[0]),
46 boost::python::extract<T2>(tuple[1]));
47 memory->convertible = storage;
50 static PyTypeObject
const* get_pytype() {
51 PyTypeObject
const* py_type = &PyTuple_Type;
55 static void registration() {
56 boost::python::converter::registry::push_back(
57 &convertible, &construct, boost::python::type_id<pair_type>()
58#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
63 boost::python::to_python_converter<pair_type, StdPairConverter, true>();