I am initialising a very large array with thousands of set values. I would like these values set at compile time rather than run time as they are fixed and will not change.
Is there a way of generating these values automatically, perhaps using the preprocessor? Currently I am generating these values using another small program then simply copying and pasting the values in respectively.
Here is what I am generating:
class MyClass
{
public:
MyClass(int x, int y, int z) : X(x), Y(y), Z(z) {}
int X, Y, Z;
};
std::vector<MyClass> my_vector{
#include "my_vector_default_values.h"
};
my_vector_default_values.h
MyClass(0, 0, 1),
MyClass(0, 0, 2),
MyClass(0, 0, 3),
MyClass(0, 0, 4),
// etc... for thousands of lines
// ...
Edit:
The actual values I am generating are generated as follows (this is the C# program):
var sb = new StringBuilder();
var sizeX = 32;
var sizeY = 32;
var sizeZ = 32;
for (var x = 0; x < sizeX; x++)
{
for (var y = 0; y < sizeY; y++)
{
for (var z = 0; z < sizeZ; z++)
{
sb.AppendLine($"MyClass({x}, {y}, {z}),");
}
}
}
var s = sb.ToString();