O
O
oftywave2020-12-11 22:42:05
C++ / C#
oftywave, 2020-12-11 22:42:05

How to iterate over 2 enum classes in 1 function?

enum class abc_t
{
a,
b,
c,
};

enum class tde_t
{
t,
d,
e,
};

//для перебора одного перечисляемого типа
std::string test(abc_t function)
{
switch(function)
{
case abc_t::a: return "a";
// и т.д
}
}


is it possible to do something like this?
template<typename T>
std::string test(T function)
switch(function)
{
case abc_t::a: return "a";
case tde_t:t return "t";
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Armenian Radio, 2020-12-11
@oftywave

No way. There is no introspection in C++. So the solution may be to use all sorts of crutches like boost or similar

A
Adamos, 2020-12-11
@Adamos

You need to throw out this code, forget about it and return to the problem that is solved in such a bizarre way.
Along the way, you can remember what enum actually leads to.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question