How can I use the Boost preprocessor to statically initialize an array with string and pointer pairs as shown below
#include <string>
struct Node;
struct Port
{
Port(std::string name_, Node* owner_): name(name_), owner(owner_)
{
}
std::string name;
Node* owner;
};
struct Node
{
// TODO: replace with Port port[4] = { REPEAT_SEQ(RX, 4) };
Port port[4] = {{"RX_0", this}, {"RX_1", this}, {"RX_2", this}, {"RX_3", this}};
};
int main()
{
Node node;
}
The problem is that some nodes have lots of ports and writing these port name and owner pointer pairs is tedious and error prone.
I'd like to automate it with the Boost Preprocessor, for example REPEAT_SEQ(RX, 4)