79162841

Date: 2024-11-06 13:45:00
Score: 1
Natty:
Report link

If the only use cases that you (will) have are char[4], char[4], uint16_t, and float, then following the advice of @Jarod42 and @463035818_is_not_an_ai is enough. If there's more, and since you have used the tag oop, I propose the following option:

Instead of enumerating your Tags, define a small class for each Tag item, and have a virtual method for handling t. Delegate handling what to do with t in the classes you derive from here.

A partial answer would be as follows:

template <typename T>
class Tag {
public:
  virtual void operator() (T& t) = 0;
};

template <typename T>
class A : public Tag<T> {
public:
  void operator() (T& t) override {
    printf("D: A::operator()\n");
  }
};

template <typename T>
class B : public Tag<T> {
public:
  void operator() (T& t) override {
    printf("D: B::operator()\n");
  }
};
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Jarod42
  • User mentioned (0): @463035818_is_not_an_ai
  • Low reputation (1):
Posted by: Mahyar