You are viewing a single comment's thread. Return to all comments →
enum class Fruit { apple, orange, pear }; enum class Color { red, green, orange }; map<Fruit, string> fruits { {Fruit::apple, "apple"}, {Fruit::orange, "orange"}, {Fruit::pear, "pear"}}; map<Color, string> color { {Color::red, "red"}, {Color::green, "green"}, {Color::orange, "orange"}}; template <typename T> struct Traits; template <> struct Traits <Fruit> { static string name(int idx) { auto iter = fruits.find(( Fruit ) idx); return iter != fruits.end() ? iter->second : "unknown"; } }; template <> struct Traits <Color> { static string name(int idx) { auto iter = color.find(( Color ) idx); return iter != color.end() ? iter->second : "unknown"; } };
Seems like cookies are disabled on this browser, please enable them to open this website
C++ Class Template Specialization
You are viewing a single comment's thread. Return to all comments →