I am writing some generic code that would process Eigen expression differently for those that hold continuous data in memory and those do not.
I know that at run time, this can be done by checking expr.innerSize() == expr.outerStride() && expr.innerStride() == 1
but I was wondering if this could be done at compile time?
== Edit ==
The purpose of this check is to allow performing the following in generic code for expression xpr
:
// c++20
if (is_linear_accessible(xpr.data(), size)) {
auto buffer = std::span(xpr.data(), size);
// work with buffer safely
// ...
} else {
auto tmp = xpr.eval();
// work with tmp.data()
// ...
}
This way I can pass data to other libraries that work on raw buffer. As @JaMiT pointed out, since it involves run-time information, this can only be done in runtime, but I would like to utilize as many as possible the compile time information to "short curciut" the process.