Is it possible to initialize the idx value of the array_object at compile time such that member_array[0].idx = 0; member_array[1].idx = 1; ... member_array[array_size-1].idx = array_size-1. The value member of every array_object should be initialized with an empty string literal.
struct my_class {
struct array_object {
int idx;
std::string value{};
};
static constexpr size_t array_size = /* some compile time constant*/;
std::array<array_object, array_size> member_array = /* default initialize where idx of each array_object is +1 of the preceeding array_object
and the first array_object idx is 0 ; array_object value always initialized to empty string*/;
};
It is possible if you make you inner struct
constexprconstructible andconstexprcopyable.UPD: Apparently, it doesn't work on GCC. However, it works on Clang and MSVC. godbolt