Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
268 views
in Technique[技术] by (71.8m points)

c++ - less verbose way to declare multidimensional std::array

Short question: Is there a shorter way to do this

array<array<atomic<int>,n>,m> matrix;

I was hoping for something like

array< atomic< int>,n,m> matrix;    

but it doesnt work...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

A template alias might help out:

#include <array>

template <class T, unsigned I, unsigned J>
using Matrix = std::array<std::array<T, J>, I>;

int main()
{
    Matrix<int, 3, 4> matrix;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...