How inefficient would it be? It seems to me that for most cases, complex numbers would be returned at the first function evaluation.
Perhaps a start would be to evaluate the function at the limits of integration and check whether either returned value is complex. If either is, use quadgk. If not, try quadcc. If quadcc throws an error, then you can catch it and redirect to quadgk.
so, I want to catch any error messages related to complex errors and let any others pass through as normal.
the two error messages in quadcc come from:
if (fvals.length () != 1 || ! fvals(0).is_real_matrix ())
error ("quadcc: integrand F must return a single, real-valued vector")
...
and
else if (! (args(4).is_real_scalar () || args(4).is_real_matrix ()))
error ("quadcc: list of singularities (SING) must be a vector of real values");
The second one is straightforward, but I'm pretty sure integral is not set up to pass a list of singularities, so that should never appear, but can still include it in the check. The first one is annoyingly a combination of two errors. I want it to pass to quadgk if the real check fails but not if it's the length check. Might need someone who works with the C code to split that into two checks with two diff errors for this to work unless we want both failures to try quadgk first.