Last active
August 29, 2015 14:14
-
-
Save RAttab/bed7885559bdacf535d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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