I have a struct with a class member I'd like to make const because it should never be changed after the constructor:
struct S
{
S(const double pp) : p(pp){}
const double p;
};
However, I would like to create an std::array of S, of size 1000 (a size too large to explicitly construct each element).
I am aware STL array elements need a default constructor.
Is it possible to define a function called create_array() which can be used like this:
const double p = from_config("p");
std::array<S, 1000> = create_array(p);
and allow me to keep the class member as const?
std::arrayand notstd::vector?std::arrayelements require a default constructor but I have a const class member? That question is for an array of integers, not a struct/class.const, not the individual members.