identity_matrix / zero_matrix:他们分配了吗?

时间:2017-12-11 04:28:38

标签: c++ boost boost-ublas

矩阵类identity_matrixzero_matrix是具有ALLOC作为第二个参数的模板。但他们真的会分配内存吗?

1 个答案:

答案 0 :(得分:2)

不,他们不会分配内存,可以看作herehere。我认为文档具有误导性:分配器不用于初始化静态zero_one_元素,只用于T类型的构造函数:

template<class T, class ALLOC>
const typename zero_matrix<T, ALLOC>::value_type zero_matrix<T, ALLOC>::zero_ = T(/*zero*/);

...
template<class T, class ALLOC>
const typename identity_matrix<T, ALLOC>::value_type identity_matrix<T, ALLOC>::zero_ = T(/*zero*/);
template<class T, class ALLOC>
const typename identity_matrix<T, ALLOC>::value_type identity_matrix<T, ALLOC>::one_ (1); // ISSUE: need 'one'-traits here

但是,typedef size_typedifference_type是公共界面的一部分,为了保持一致,使用ALLOC::size_typeALLOC::difference_type(而不是&# 34;通常&#34; std::size_tstd::ptrdiff_t)。这是通过以下change完成的。