identity_matrix/zero_matrix:他们分配了吗?
identity_matrix/zero_matrix: do they allocate?
matrix 类 identity_matrix
和 zero_matrix
是将 ALLOC
作为第二个参数的模板。但是他们真的分配内存吗?
不,它们不分配内存,可以看出here and here. I think the documentation is misleading: allocators are not used for initialization of static zero_
or 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
然而,typedefs size_type
和 difference_type
是 public 接口的一部分,为了保持一致,使用了 ALLOC::size_type
和 ALLOC::difference_type
(而不是 "usual" std::size_t
和 std::ptrdiff_t
)。这是通过以下 change.
完成的
matrix 类 identity_matrix
和 zero_matrix
是将 ALLOC
作为第二个参数的模板。但是他们真的分配内存吗?
不,它们不分配内存,可以看出here and here. I think the documentation is misleading: allocators are not used for initialization of static zero_
or 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
然而,typedefs size_type
和 difference_type
是 public 接口的一部分,为了保持一致,使用了 ALLOC::size_type
和 ALLOC::difference_type
(而不是 "usual" std::size_t
和 std::ptrdiff_t
)。这是通过以下 change.