I have the following piece of code (I apologize for the slightly larger code snippet, this is the minimal example I was able to reduce my problem to):
#inclu
It probably has a lazy evaluation type that is only safe to evaluate once. You could capture it with:
auto autoresultmatrix = autoresult.eval()
The problem is that Id() returns a temporary which is stored by reference in the object representing the expression Id(Foo, 4) * v. Thus after the auto statement, autoresult stores a reference to a dead object. If you do not want an abstract expression but the actual result, do not use auto or call eval to enforce evaluation:
auto autoresult = (Id(Foo, 4) * v).eval();
A third option is to make the object returned by Id() available for further computations:
auto id4 = Id(Foo,4);
auto autoresult = id4 * v;
but in this case, anytime you use autoresult then the product will be re-evaluated and the following will output different results:
cout << autoresult;
v.setRandom();
cout << autoresult;