Let's consider following illustrative example code:
using matrix_t = double[2][2];
constexpr matrix_t zero_matrix = {
{0.0, 0.0},
{0.0, 0.0}
};
constexpr matrix_t identity_matrix = {
{1.0, 0.0},
{0.0, 1.0}
};
struct wrapped_matrix_t
{
matrix_t matrix;
};
constexpr wrapped_matrix_t zero_wrapped_matrix = {
//zero_matrix
{
{zero_matrix[0][0], zero_matrix[0][1]},
{zero_matrix[1][0], zero_matrix[1][1]}
}
};
constexpr wrapped_matrix_t identity_wrapped_matrix = {
//identity_matrix
{
{identity_matrix[0][0], identity_matrix[0][1]},
{identity_matrix[1][0], identity_matrix[1][1]}
}
};
Now I would like to be able to use by constexpr arrays zero_matrix and identity_matrix to initialize matrix_t members in other types. However that seems to not be possible. Or at least simple use of the name doesn't work.
The best what I come out with is reuse of values be referring to indexes. But this is far from perfect.
Is there any way to use zero_matrix and identity_matrix directly in such initializations?
(I'm checking on GCC 6.3.0 with -Wall -Wextra -pedantic -std=c++11.)
constexpr wrapped_matrix_t zero_wrapped_matrix{zero_matrix};but it doesn't compile?zero_wrapped_matrix{zero_matrix}orzero_wrapped_matrix = {zero_matrix}. In both cases I'm getting "error: array must be initialized with a brace-enclosed initializer".