I have a templated class
template <typename Data>
class C
{
.....
}
In most situations, I depend on the compiler to let me substitute types for Data.
I call methods foo(), goo() on objects of type Data, so what I substitute needs to provide
that.
I now need to substitute int and string for my Data type. I do not want to specialize
because the class is already too big and would require specializing each method (with only small code change).
My options (please tell me if there are more)
1) I can provide wrapper classes around int and string which implement the methods foo(), goo() etc
2) provide a traits class
traits that calls foo() or goo() on objects of classes that provide foo(),goo()
(these are my present substitutable classes)
and specialize these classes for int and string.
Questions
1) what are the relative merits of 1 vs 2?
2) My traits classes will have static methods. Can a traits class have non-static methods as well? I see most traits classes define constants in the STL.
3) Do I make the traits classes global or should I pass them in as a template parameter
for class C?