One approach would be to duplicate all scalar data arrays and always use typed accessors. XXGetArrayComplex() would allocate the complex array (if needed) and copy from the real side if it was not current. Copying in the other direction might also check whether the imaginary part was indeed essentially zero. Users (though sometimes not other libraries) needing array access know whether they are accessing real or complex data so they can easily call the correct accessor. The challenge of actually compiling the variations remains, but at least whatever hackery used there (macros, templates, code-generation) would not be visible to users. It's a big project however you shake it.