为什么我可以像标量矩阵一样初始化常规的Boost矩阵?

Joh*_*Doe 3 c++ boost boost-ublas

为什么这样做?它不在任何地方的文档中......

#include <iostream>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>

int main()
{

boost::numeric::ublas::matrix<double> twoByTwoMat(2,2,-2);

std::cout << "This is the matrix: " << twoByTwoMat << std::endl;

return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:

This is the matrix: [2,2]((-2,-2),(-2,-2))
Run Code Online (Sandbox Code Playgroud)

lcs*_*lcs 5

它在<boost/numeric/ublas/matrix.hpp>头文件中定义.

matrix (size_type size1, size_type size2, const value_type &init):
        matrix_container<self_type> (),
        size1_ (size1), size2_ (size2), data_ (layout_type::storage_size (size1, size2), init) {
    }
Run Code Online (Sandbox Code Playgroud)