I have the following code:
enum class MessageDeliveryMethod { POST_MASTER, BUBBLE, NUM_ENUMERATORS }; namespace { using MapType = std::array< std::pair<char const*, MessageDeliveryMethod>, static_cast<std::size_t>(MessageDeliveryMethod::NUM_ENUMERATORS) >; MapType g_mapping = {{ {"POST_MASTER", MessageDeliveryMethod::POST_MASTER}, {"BUBBLE", MessageDeliveryMethod::BUBBLE}, }}; }
This compiles, but I donโt know why. The g_mapping variable requires an extra layer of seemingly redundant curly braces. In other words, I expect initialization to look like this:
MapType g_mapping = { {"POST_MASTER", MessageDeliveryMethod::POST_MASTER}, {"BUBBLE", MessageDeliveryMethod::BUBBLE}, };
(One level of outer braces removed).
I understand that prior to C ++ 14, direct initialization requires an extra level of curly braces. However, copy initialization should not require this based on this page (look at the example there).
Can anyone explain this?
UPDATE:
This SO question , which is supposed to be duplicated by my question, really answers some specific and useful questions (related to my own), however, out of context, mine got confused due to the use of pair (which, as I thought, was initially causing the problem). I would never have found this question in the first place, therefore, if something that I think is possible, as I formulated my question, can help people come to a solution from different angles.
c ++ c ++ 11
void.pointer
source share