I have a class with several members of "similar" type like:
class Container {
C1 c1;
C2 c2;
C3 c3;
....
template <typename T>
const T& get() {
????
}
};
The class has a templated method get<T>()
which can be used to get a reference to the member of type T
- i.e.
Container cont;
const auto& c1 = cont.get<C1>();
to access the c1
member. The current implementation of get<T>()
is based on specialization for all the types represented in the Container
class. Is there an elegant way to achieve the same without manually implementing the specializations?