I've poked around on stackoverflow for a while, but either I don't understand templates enough to find a solution, or it simply hasn't been answered before.
In this example:
template <typename T> T f();
Is it possible to make the function require type T to be a specialization of the std::basic_string
template?
I could have the template defined with T as the type of the std::basic_string
as so (using std::basic_string<T>
internally, of course):
template <typename T> std::basic_string<T> f();
But then I would not be able to pass std::string
or std::wstring
to the function (expecting the return type to be std::string
and std::wstring
, respectively), which is the real aim here (to be able to pass any type which derives from the std::basic_string
template).