I have a more complex version of the following code:
#include <array>
#include <cmath>
using namespace std;
class Dummy
{
public:
Dummy(const double a, const double f)
{
}
};
constexpr double values[] { 0.1, 0.2, 0.3, 0.4 };
constexpr auto N = sizeof(values) / sizeof(values[0]);
static const array<Dummy, N> dummies {Dummy(10 * values[0], M_PI * 0),
Dummy(10 * values[1], M_PI * 1),
Dummy(10 * values[2], M_PI * 2),
Dummy(10 * values[3], M_PI * 3)};
int main()
{
return 0;
}
I would like to simplify the initialization of the array dummiesas it is very redundant. However, I am associated with C ++ 11, and I cannot change the class Dummyto have a constructor constexpr(which would greatly simplify my situation).
I looked at the variable templates, but it doesn’t seem to get around the fact that the constructor is Dummynot constexpr:
template<size_t... Is>
struct _Helper
{
static constexpr array<Dummy, N> dummies {Dummy(10 * values[Is], M_PI * Is)...};
};
static const array<Dummy, N> dummies { _Helper<0, 1, 2, 3>::dummies };
Are there other ways to simplify array initialization? valuescan be replaced as literally by any other that can be converted back to double[]at runtime.