samedi 2 mars 2019

Ideal architecture design for namespace parameters

I have 2 header files

a1.h

namespace a
{
  enum abc:uint8
  {
      abc1 = 1
      abc2 = 2
  };
}

and a2.h

namespace b
{
  enum abc:uint8
  {
      abc1 = 1
      abc2 = 2
      abc3 = 3
  };
}

I want to apply some operation dosomething(a::abc / b::abc) on the enum. The easiest solution would be to write two separate functions for different namespaces.

I am wondering if dosomething function can be templatized given 1. Enum values are same 2. Enum values are different. This would avoid code duplication and make the design extendable.

I have constraint that I cannot modify header files.

Aucun commentaire:

Enregistrer un commentaire