矩阵类identity_matrix
和zero_matrix
模板ALLOC
作为第二个参数。但是他们真的分配内存吗?
问问题
34 次
1 回答
2
不,他们不分配内存,可以在这里 和这里看到。我认为文档具有误导性:分配器不用于静态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
但是,typedefsize_type
和difference_type
是公共接口的一部分,为了保持一致,使用了ALLOC::size_type
and ALLOC::difference_type
(而不是“通常”的std::size_t
and std::ptrdiff_t
)。这是通过以下更改完成的。
于 2017-12-11T06:49:00.543 回答