I want to know what is the best way to create 2d arrays in C++ when the length is fixed and known at compile time. There are two options:
// Option #1: std::array with native arrays as elements
std::array<float[4], 4> test_2d_array{ {
{0.7, 0.3, 0.5, 0.1},
{0.7, 0.3, 0.5, 0.1},
{0.7, 0.3, 0.5, 0.1},
{0.7, 0.3, 0.5, 0.1}
} };
// Option #2: std::array with nested std::array elements
std::array<std::array<float, 4>, 4> test_2d_array_v2{ {
{0.7, 0.3, 0.5, 0.1},
{0.7, 0.3, 0.5, 0.1},
{0.7, 0.3, 0.5, 0.1},
{0.7, 0.3, 0.5, 0.1}
} };
Which one is to be preferred? What are the things to keep in mind?
Aucun commentaire:
Enregistrer un commentaire