I run into a situation where I want to use a type alias in the template but don't know how, here's a contrived example:
class Example {
public:
using A = std::tuple<int, float>;
using B = std::tuple<int, double>;
using C = std::tuple<int, double>;
.... // possibly many other type aliases
template<typename T>
void Foo(const T& value) {
// do sth ...
}
};
I understand that A, B and C are merely aliases of the original std::tuple type, they do not create new types, so in this example, B and C are different names referring to the same type std::tuple<int, double>.
In my case, T is going to be one of A, B and C, since B is identical to C, the compiler will only generate 2 versions of Foo(), but I want it to treat B and C differently. The obvious solution is to replace std::tuple with struct which defines a new type, but that would make the code a lot more messy and lose the ability of using structured bindings. Is there a more elegant way of achieving this? Or should I prefer using struct in this case?