Skip to content

Instantly share code, notes, and snippets.

@RAttab
Last active August 29, 2015 14:14
Show Gist options
  • Save RAttab/bed7885559bdacf535d6 to your computer and use it in GitHub Desktop.
Save RAttab/bed7885559bdacf535d6 to your computer and use it in GitHub Desktop.
template<typename... Args>
struct TupleConverter
{
typedef boost::python::list PyTuple;
static void* convertible(PyObject* obj)
{
boost::python::extract<PyTuple> tupleExtract(obj);
if (!tupleExtract.check()) return nullptr;
PyTuple tuple = tupleExtract();
if (boost::python::len(tuple) != sizeof...(Args)) return nullptr;
if (!check<0, Args...>(tuple))
return nullptr;
return obj;
}
template<size_t Index, typename Arg, typename... Rest>
static bool check(PyTuple tuple)
{
boost::python::extract<Arg> extract(tuple[Index]);
if (!extract.check()) {
return false;
}
return check<Index+1, Rest...>(tuple);
}
template<size_t Index>
static bool check(PyTuple tuple)
{
return true;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment