As a style, you may need to highlight parts that differ from each other as a trivial class of templates that more easily specializes. As an example of this method, consider your favorite implementation of an unordered set pattern (or hash_set). Such implementations require you to specialize in a simple hash_key <T> if no specialization already exists. They do not require you to specialize a full container.
Although your example is simple enough to just specialize the whole function, in general, I would implement Func <T> in general and specialize in DoSomethingSpecial <T> like this:
template< class T > void DoSomethingSpecial(T &input) { ... } template< class T > void Func(T input) { DoSomethingGeneral1(); ... DoSomethingSpecial(T); ... DoSomethingGeneral2(); } template<> void DoSomethingSpecial(std::string &input) { ... } template<> void DoSomethingSpecial(int &input) { ... }
source share