Python: C++ extension returning multiple values
<p>I am writing a C++ extension for python script and want to return multiple values like what we can do in python function.</p>

<p>Simple Example in python:</p>

<pre><code>def test():
    return 0,0
</code></pre>

<p><strong>tuple</strong> seems to be the closest answer</p>

<pre><code>#include &lt;tuple&gt;

std::tuple&lt;int,int&gt; test(void){
return std::make_tuple(0,0);
}
</code></pre>

<p>But when I compile it, it complains that </p>

<pre><code>TypeError: No to_python (by-value) converter found for C++ type: std::tuple&lt;int, int&gt;
</code></pre>

<p>Anyone knows if I could return multiple values using C++?</p>

<p><strong>EDIT:</strong></p>

<p>This is my setup.py file.</p>

<pre><code>#!/usr/bin/env python

from distutils.core import setup
from distutils.extension import Extension

setup(name="PackageName",
    ext_modules=[
        Extension("foo", ["foo.cpp"],
        libraries = ["boost_python"],
        extra_compile_args = ["-std=c++11"]
        )
    ])
</code></pre>

<p>It seems you're using boost-python. Then should use boost::python::tuple, not std::tuple. See the examples on <a href="http://www.boost.org/doc/libs/1_61_0/libs/python/doc/html/reference/object_wrappers/boost_python_tuple_hpp.html#object_wrappers.boost_python_tuple_hpp.introduction" rel="nofollow">this page</a>.</p>

python c++ python-c-api python-c-extension