3

With C++ scoped enums, I have to write, for example:

enum class matrix_type_t { BINARY, INTEGER, REAL, COMPLEX };

std::string matrix_type_str(matrix_type_t type) {
   switch (type) {
      case matrix_type_t::BINARY:
         return std::string("binary");
      case matrix_type_t::INTEGER:
      ...
   }
}

However, if the context is clear, I would prefer:

std::string matrix_type_str(matrix_type_t type) {
   ??? // e.g. something as: using matrix_type_t::;
   switch (type) {
      case BINARY:
         return std::string("binary");
      case INTEGER:
      ...
   }
}

Is this possible to achieve somehow? If not, wouldn't it be worth considering for future C++?

Daniel Langr
  • 22,196
  • 3
  • 50
  • 93
  • @mcmlxxxvi Close, but I don't want to make aliases for all the enum identifiers, I would like to bring them all at once into the current scope. – Daniel Langr May 10 '16 at 08:53
  • I understand you. I don't know the answer, but according to that question, `using` won't help. Personally, I like the enums being scoped. – mcmlxxxvi May 10 '16 at 09:05
  • 2
    To chime in once more, [these answers](http://stackoverflow.com/questions/9450338/equivalent-of-using-namespace-x-for-scoped-enumerations) say that, indeed, it's not possible. – mcmlxxxvi May 10 '16 at 09:09
  • 1
    @mcmlxxxvi Thanks, haven't found that question under its name. I like scoped enums too, but avoiding to type their names would simplify my codes in some cases. – Daniel Langr May 10 '16 at 11:00

0 Answers0