Are there any limitations using boost's mapped_matrix with non-copyable objects like std::unique_ptr? I'm on VS2017 in C++14 mode.
#include <memory>
#include "boost/numeric/ublas/matrix_sparse.hpp"
class myClass
{
public:
myClass() {}
void myMethod() {}
/*...*/
};
void f()
{
boost::numeric::ublas::mapped_matrix<std::unique_ptr<myClass>> SparseValues;
//SparseValues(0, 0) = std::make_unique<myClass>(); // C2280, is it impossible to assign as the move assignment seems to be missing?
auto p = std::make_unique<myClass>();
//SparseValues(0, 0) = std::move(p); // C2280
auto a = SparseValues(0, 0); // Succeeds?? Expected it to fail, assuming it attempts to create a copy?
auto &b = SparseValues(0, 0); // C4239: warning nonstandard extension used
//auto c = SparseValues(0, 0).operator()(); // C2280, documentation for operator() says "Returns a reference of the j-th element in the i-th row", so there should be no copy?!
auto &d = SparseValues(0, 0).operator()(); // Suceeds??
//auto e = SparseValues(0, 0).ref(); // C2280, ref() is not ducumented but was worth a try
//auto &f = SparseValues(0, 0).ref(); // C2440
// OK, it seems not possible to get a reference, so then let's directly try to access an internal object:
// Check for nullptr:
//if (!SparseValues(0, 0)) { /*...*/ } // Test for null: C2678, C2088
//if (!SparseValues(0, 0)()) { /*...*/ } // Test for null: C2678, C2088
//if (!SparseValues(0, 0).ref()) { /*...*/ } // Test for null: C2240
//SparseValues(0, 0) = std::make_unique<myClass>(); // Reassign: C2280
//SparseValues(0, 0)->myMethod(); // Call method: C2819, C2039
//SparseValues(0, 0)()->myMethod(); // Call method: C2819, C2039
//SparseValues(0, 0).ref()->myMethod(); // Call method: C2280
//a = std::move(p); // Assignment: C2280
//b = std::move(p); // Assignment: C2280
//d = std::move(p); // Assignment: C2679
}
So this looks pretty useles to me! My questions are:
- Is mapped_matrix indeed incapable to deal with uncopyable objects?
- Is this by intention (due to architectural problems), or should I file a bugreport on this?
- If however it can be used with non-copyables, how to properly use it?
- The documentation of mapped_matrix is pretty, hm, poor. Anyone has another link giving more information? Like
- What is the usage scenario of the functor and ref()? Is it correct that ref() guarantees that an object in the matrix exists (and if it'd be a default constructed object)?
- What is the difference between the type "reference" returned by the functor and "true_refrence" returned by insert_element()? Sounds like the implementation bleeds through here?
- What is the usage scenario of method assign_temporary()?
My workaround is of course to use std::shared_ptr, there it compiles without a problem...