Neargye / magic_enum

Static reflection for enums (to string, from string, iteration) for modern C++, work with any enum type without any macro or boilerplate code
MIT License
4.76k stars 422 forks source link

magic_enum::containers::array initialization doesn't work with enum containing more than 128 enum values #327

Closed Scout22 closed 8 months ago

Scout22 commented 8 months ago

When defining a magic_enum::containers::array with more than 128 enum values does not compile with the following error:

error: too many initializers for ‘std::__array_traits<ColorRGB, 128>::_Type’ {aka ‘ColorRGB [128]’}

Example of code that doesn't compile

` enum class ColorName : std::uint16_t { Snow, GhostWhite, WhiteSmoke, Gainsboro, FloralWhite, OldLace, Linen, AntiqueWhite, PapayaWhip, BlanchedAlmond, Bisque, PeachPuff, NavajoWhite, Moccasin, Cornsilk, Ivory, LemonChiffon, Seashell, Honeydew, MintCream, Azure, AliceBlue, Lavender, LavenderBlush, MistyRose, White, Black, DarkSlateGray, DarkSlateGrey, DimGray, DimGrey, SlateGray, SlateGrey, LightSlateGray, LightSlateGrey, Gray, Grey, LightGrey, LightGray, MidnightBlue, Navy, NavyBlue, CornflowerBlue, DarkSlateBlue, SlateBlue, MediumSlateBlue, LightSlateBlue, MediumBlue, RoyalBlue, Blue, DodgerBlue, DeepSkyBlue, SkyBlue, LightSkyBlue, SteelBlue, LightSteelBlue, LightBlue, PowderBlue, PaleTurquoise, DarkTurquoise, MediumTurquoise, Turquoise, Cyan, LightCyan, CadetBlue, MediumAquamarine, Aquamarine, DarkGreen, DarkOliveGreen, DarkSeaGreen, SeaGreen, MediumSeaGreen, LightSeaGreen, PaleGreen, SpringGreen, LawnGreen, Green, Chartreuse, MediumSpringGreen, GreenYellow, LimeGreen, YellowGreen, ForestGreen, OliveDrab, DarkKhaki, Khaki, PaleGoldenrod, LightGoldenrodYellow, LightYellow, Yellow, Gold, LightGoldenrod, Goldenrod, DarkGoldenrod, RosyBrown, IndianRed, SaddleBrown, Sienna, Peru, Burlywood, Beige, Wheat, SandyBrown, Tan, Chocolate, Firebrick, Brown, DarkSalmon, Salmon, LightSalmon, Orange, DarkOrange, Coral, LightCoral, Tomato, OrangeRed, Red, HotPink, DeepPink, Pink, LightPink, PaleVioletRed, Maroon, MediumVioletRed, VioletRed, Magenta, Violet, Plum, Dummy1, Dummy2, Dummy3, Dummy4

};

constexpr magic_enum::containers::array<ColorName, k1::common::types::ColorRGB> colors_with_names{{{

  {255, 250, 250}, {248, 248, 255}, {245, 245, 245}, {220, 220, 220}, {255, 250, 240}, {253, 245, 230},
  {250, 240, 230}, {250, 235, 215}, {255, 239, 213}, {255, 235, 205}, {255, 228, 196}, {255, 218, 185},
  {255, 222, 173}, {255, 228, 181}, {255, 248, 220}, {255, 255, 240}, {255, 250, 205}, {255, 245, 238},
  {240, 255, 240}, {245, 255, 250}, {240, 255, 255}, {240, 248, 255}, {230, 230, 250}, {255, 240, 245},
  {255, 228, 225}, {255, 255, 255}, {0, 0, 0},       {47, 79, 79},    {47, 79, 79},    {105, 105, 105},
  {105, 105, 105}, {112, 128, 144}, {112, 128, 144}, {119, 136, 153}, {119, 136, 153}, {190, 190, 190},
  {190, 190, 190}, {211, 211, 211}, {211, 211, 211}, {25, 25, 112},   {0, 0, 128},     {0, 0, 128},
  {100, 149, 237}, {72, 61, 139},   {106, 90, 205},  {123, 104, 238}, {132, 112, 255}, {0, 0, 205},
  {65, 105, 225},  {0, 0, 255},     {30, 144, 255},  {0, 191, 255},   {135, 206, 235}, {135, 206, 250},
  {70, 130, 180},  {176, 196, 222}, {173, 216, 230}, {176, 224, 230}, {175, 238, 238}, {0, 206, 209},
  {72, 209, 204},  {64, 224, 208},  {0, 255, 255},   {224, 255, 255}, {95, 158, 160},  {102, 205, 170},
  {127, 255, 212}, {0, 100, 0},     {85, 107, 47},   {143, 188, 143}, {46, 139, 87},   {60, 179, 113},
  {32, 178, 170},  {152, 251, 152}, {0, 255, 127},   {124, 252, 0},   {0, 255, 0},     {127, 255, 0},
  {0, 250, 154},   {173, 255, 47},  {50, 205, 50},   {154, 205, 50},  {34, 139, 34},   {107, 142, 35},
  {189, 183, 107}, {240, 230, 140}, {238, 232, 170}, {250, 250, 210}, {255, 255, 224}, {255, 255, 0},
  {255, 215, 0},   {238, 221, 130}, {218, 165, 32},  {184, 134, 11},  {188, 143, 143}, {205, 92, 92},
  {139, 69, 19},   {160, 82, 45},   {205, 133, 63},  {222, 184, 135}, {245, 245, 220}, {245, 222, 179},
  {244, 164, 96},  {210, 180, 140}, {210, 105, 30},  {178, 34, 34},   {165, 42, 42},   {233, 150, 122},
  {250, 128, 114}, {255, 160, 122}, {255, 165, 0},   {255, 140, 0},   {255, 127, 80},  {240, 128, 128},
  {255, 99, 71},   {255, 69, 0},    {255, 0, 0},     {255, 105, 180}, {255, 20, 147},  {255, 192, 203},
  {255, 182, 193}, {219, 112, 147}, {176, 48, 96},   {199, 21, 133},  {208, 32, 144},  {255, 0, 255},
  {238, 130, 238}, {221, 160, 221}, {1, 1, 1},       {1, 1, 1},       {1, 1, 1},       {1, 1, 1}}}};`
Neargye commented 8 months ago

These errors mean that the library did not reflect all the enum values. ColorName::Dummy4 = 131, By default MAGIC_ENUM_RANGE_MIN = -128, MAGIC_ENUM_RANGE_MAX = 128.

Check more in https://github.com/Neargye/magic_enum/blob/master/doc/limitations.md