Given this code:
#include <string>
#include <vector>
#include <iostream>
template <typename T>
std::string stringify(const T&) {
return "{?}";
}
template <typename T>
std::string proxy(const T& in) {
return stringify(in);
}
// trying to specialize "stringify()"
template <typename T>
std::string stringify(const std::vector<T>& in) {
return "vector specialization!";
}
template <>
std::string stringify(const std::vector<int>& in) {
return "INT vector specialization!";
}
int main() {
std::cout << proxy(1); // calls the 1st
std::vector<int> intVec;
std::cout << proxy(intVec); // calls the 1st
std::vector<double> dblVec;
std::cout << proxy(dblVec); // calls the 1st
return 0;
}
How can I specialize stringify() for vector<> after proxy<>?
Currently I get {?}{?}{?}
If I delete this one - stringify(const std::vector<T>& in) then the vector<int> starts getting called because it would be a specialization of the first.
Then I would get {?}INT vector specialization!{?}
Is there any way to call any of the 2 vector specialization stringification functions from proxy() - if they are defined last - after the proxy() function?
Is there a way to partially specialize on vector<> and still get called from proxy<>?
I don't want to specialize for vector<int>, vector<double>, vector<UserType>...
EDIT: forgot to mention I need this for C++98