sharkdp/dbg-macro

Fails with Eigen matrices

roger- opened this issue · 7 comments

roger- commented

When trying to print Eigen::MatrixXd objects I get an assertion. Eigen::VectorXd objects work though.

Any ideas?

@roger- Could you please share a minimal example to reproduce the issue?

roger- commented

Sure:

Eigen::MatrixXd X(2, 2);
X.setIdentity();

dbg(X);

@roger- I am unable to reproduce the issue. It might be specific to your arch/compiler/c++ std/eigen version.
Here is my attempt - https://godbolt.org/z/Gc8Y1WhMr
Could you try reproducing your issue in godbolt and share it here?

roger- commented

Looks like it fails with Eigen 3.4: https://godbolt.org/z/o8vYzGnWo

Thank you for reporting this. The problem seems to be that we treat the Eigen matrix as a container via this piece of code:

dbg-macro/dbg.h

Lines 382 to 389 in 1aaa880

template <typename T>
struct is_container {
static constexpr bool value =
is_detected<detect_begin_t, T>::value &&
is_detected<detect_end_t, T>::value &&
is_detected<detect_size_t, T>::value &&
!std::is_same<std::string, remove_cvref_t<T>>::value;
};

I guess that would need to be adapted in order to fix the Eigen matrix case.

@sharkdp What should be the approach here? From what I understand we have two options,

  1. Eigen is not part of the std library. We should fail when trying to dbg(...) Eigen objects and expect the user to add overloads in such scenarios
  2. Add support for Eigen

I would go with (1) if given the option

It's kind of Eigen's fault, in my opinion. They provide .begin() and .end() for Eigen::MatrixXd, but you're not allowed to use them (will result in a static assertion failing). This makes it hard to detect with meta programming. We could maybe forward-declare and special-case it somehow, but I'm not sure if that's a scalable approach.