S
sheffmail
I have the following code:
template <class T>
struct MyS
{
};
template<class T>
inline const T& function(const std::locale& loc)
{
std::cout << "generic" << std::endl;
}
template <class CharType, class Traits, class Allocator>
std::cout << "specialized" << std::endl;
}
int main(int argc, char* argv[])
{
function< MyS<std::string> >(std::locale()); //Should print
"specialized"
function< MyS<std::wstring> >(std::locale()); //Should print
"specialized"
function< MyS<int> >(std::locale()); //Should print "generic"
return 0;
}
Which doesn't compile, I believe it's because you can't partially
specialize function templates. But I really need to
get the desired behavior(Note the "Should print"s in comments), how
can this be done ?
template <class T>
struct MyS
{
};
template<class T>
inline const T& function(const std::locale& loc)
{
std::cout << "generic" << std::endl;
}
template <class CharType, class Traits, class Allocator>
{inline const MyS said:(const std::locale& loc)
std::cout << "specialized" << std::endl;
}
int main(int argc, char* argv[])
{
function< MyS<std::string> >(std::locale()); //Should print
"specialized"
function< MyS<std::wstring> >(std::locale()); //Should print
"specialized"
function< MyS<int> >(std::locale()); //Should print "generic"
return 0;
}
Which doesn't compile, I believe it's because you can't partially
specialize function templates. But I really need to
get the desired behavior(Note the "Should print"s in comments), how
can this be done ?