0

I'm using better enums package
Having 1:1 mapping between better enum values and better enum types/functionality
For example

  • better enum A[a1, a2]
  • better enum B1
  • better enum B2

So the logical mapping is:

  • A::a1 mapped to B1 type
  • A:a2 mapped to B2 type
   BETTER_ENUM(A, int, a1, a2)
   BETTER_ENUM(B1, int, b11, b12, b13)
   BETTER_ENUM(B2, int, b21, b22, b23, b24)

Obviously the above example is of size two, but real code would have to support its growth
So basically in order to support this mapping used switch case as below, but this code is hard to maintain and extend:

bool Execute1(A a_val)
{
    switch (a_val)
    {
    case A::a1:
        return execute1<B1>();
    case A::a2:
        return execute1<B2>();
    default:
        break;
    }

    return false;
}

int Execute2(A a_val)
{
    switch (a_val)
    {
    case A::a1:
        return execute2<B1>();
    case A::a2:
        return execute2<B2>();
    default:
        break;
    }

    return 0;
}

Any ideas how to generalize this mapping , and use some design pattern that doesn't require as above switch/case?

Roman
  • 21
  • 5
  • 1
    How do you use `a1` or `a2`? Runtime variable or constexpr variable? – 김선달 Apr 08 '21 at 14:12
  • given by user, it's not constexpr, "Execute" methods get arbitrary values when called – Roman Apr 08 '21 at 14:16
  • seems there is already similar question asked [here](https://stackoverflow.com/questions/5694255/boost-how-to-create-a-map-for-types-selection) – Roman Apr 10 '21 at 09:03

0 Answers0