Migrated from the original repository
Original issue: serge-sans-paille/frozen#111
Originally reported by: @ivan-aksamentov
I would like nested containers to have different sizes (all known at compile time). Is this possible?
For example, consider this map of sets:
// This dimension is variable V
using Set = frozen::set<frozen::string, 3>;
constexpr frozen::map<frozen::string, Set, 4> table = {
{"one", {"A"}},
{"two", {"B", "C"}},
{"three", {"D", "E", "F"}},
{"-", {}},
};
And its usage:
const auto& two = table.find("two");
// two is {"B", "C"}
const auto& three = table.find("three");
// three is {"D", "E", "F"}
As you see, sets inside the map have different length.
This currently won't compile:
error: no matching constructor for initialization of 'const frozen::map<frozen::string, Set, 4>'
I thought, if sets really need to be of the same size, then maybe we could fill them with some dummy values, for example "?":
constexpr frozen::map<frozen::string, Set, 4> table = {
{"one", {"A", "?", "?"}},
{"two", {"B", "C", "?"}},
{"three", {"D", "E", "F"}},
{"-", {"?", "?", "?"}},
};
I can handle these dummy values in userspace and make sure I never search for "?" in these sets, but from inside the library it can probably be handled more efficiently.
Application: reverse translation in biology. I need a lookup table to find a set of possible triplets (value of the map) for a given amino acid (key of the map). The sets are at most 6 elements. This table is fundamental to biology and never changes, so runtime initialization would be certainly wasteful.
Any other ideas on how this can be implemented without runtime initialization and associated static initialization order fiasco etc.?
I would like nested containers to have different sizes (all known at compile time). Is this possible?
For example, consider this map of sets:
And its usage:
As you see, sets inside the map have different length.
This currently won't compile:
I thought, if sets really need to be of the same size, then maybe we could fill them with some dummy values, for example
"?":I can handle these dummy values in userspace and make sure I never search for
"?"in these sets, but from inside the library it can probably be handled more efficiently.Application: reverse translation in biology. I need a lookup table to find a set of possible triplets (value of the map) for a given amino acid (key of the map). The sets are at most 6 elements. This table is fundamental to biology and never changes, so runtime initialization would be certainly wasteful.
Any other ideas on how this can be implemented without runtime initialization and associated static initialization order fiasco etc.?