矩阵类identity_matrix
和zero_matrix
是具有ALLOC
作为第二个参数的模板。但他们真的会分配内存吗?
答案 0 :(得分:2)
不,他们不会分配内存,可以看作here和here。我认为文档具有误导性:分配器不用于初始化静态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_type
和difference_type
是公共界面的一部分,为了保持一致,使用ALLOC::size_type
和ALLOC::difference_type
(而不是&# 34;通常&#34; std::size_t
和std::ptrdiff_t
)。这是通过以下change完成的。