I have a binary format that I'm writing encoders and decoders for. Almost all of the binary types directly map to primitives, except for two container types, a list and a map type that can contain any of the other types in the format including themselves.
These feel like they just want to be a typedef of std::variant
typedef std::variant<std::vector<char>, std::vector<int>, ...> ListType
But because I need to be able to contain a vector of ListType itself I end up doing this
struct ListType {
std::variant<std::vector<char>, std::vector<int>, ..., std::vector<ListType>> value;
}
Which adds a little friction to using the type. There's really no other state to these variables to justify encapsulating them.
Typing it out I realizing I'm asking "Can you forward declare a template?" which seems a stupid question. Still, anyone got a better strategy for this?