Input Format
The first line contains , the number of test cases.
Each of the  subsequent lines contains two space-separated integers. The first integer is a color value, , and the second integer is a fruit value, .
Constraints
Output Format
The locked stub code in your editor prints  lines containing the color name and the fruit name corresponding to the input enumeration index.

hackerrank c++ class template specialization problem solution

C++ class Template specialization problem solution | HackerRank

template <>
struct Traits<Fruit> {
  static const int min = static_cast<int>(Fruit::apple);
  static const int max = static_cast<int>(Fruit::pear);

  static const char *name(int index)
  {
    if (index<min || index>max) {
      return "unknown";
    }
    switch (static_cast<Fruit>(index)) {
      case Fruit::apple:  return "apple";
      case Fruit::orange: return "orange";
      case Fruit::pear:   return "pear";
    }
    return "";
  }
};

template <>
struct Traits<Color> {
  static const int min = static_cast<int>(Color::red);
  static const int max = static_cast<int>(Color::orange);

  static const char *name(int index)
  {
    if (index<min || index>max) {
      return "unknown";
    }
    switch (static_cast<Color>(index)) {
      case Color::red:    return "red";
      case Color::green:  return "green";
      case Color::orange: return "orange";
    }
    return "";
  }
};