less verbose way to declare multidimensional std::array

前端 未结 5 737
再見小時候
再見小時候 2020-12-05 11:11

Short question: Is there a shorter way to do this

array,n>,m> matrix;

I was hoping for something like

5条回答
  •  佛祖请我去吃肉
    2020-12-05 11:44

    A palatable workaround for compilers that don't support template aliases yet is to use a simple metafunction to generate the type:

    #include 
    #include 
    
    template
    struct Matrix
    {
        typedef std::array, RowsN> type; // row major
    
    private:
        Matrix(); // prevent accidental construction of the metafunction itself
    };
    
    int main()
    {
        Matrix::type matrix;
    }
    

提交回复
热议问题