Simple question, how to initialize a map of arrays (or some other container type) of different sizes? For example:
enum class code {A,B,C};
enum class res {X1,X2,X3,X4,X5};
std::map<code, ?> name {
{code:A, {res::X1,res::X2}},
{code:B, {res::X2,res::X3, res::X4}},
{code:C, {res::X5}}
};
I need to find at compile time if res::X2
is in map name
at code::B
This expression should, I think, check for that using static_assert
:
constexpr bool validate(code t, res p, int i = 0) {
return (name[t][i] == p ? true : ((sizeof(name[t]) == (i+1)) ? false :validate(t, p, ++i)));
}
Because validate
is a constexpr
a basic array would work but how to define it in a map argument as an array of type res
? And that each array could be different in size?
So, I've made a mistake. I was under the impression that map can be accessed in constexpr function. What container type can you suggest me that would allow me to achieve what I have written above?
>?
– Leon Aug 01 '16 at 15:30