M
mliptak
Hi, I need to specialize one operation in a template class, when the
parameter is a template itself.
Suppose this code:
#include <string>
template <typename T>
struct Nullable
{};
template <typename T>
class A
{
public:
void fn(const std::string& s)
{}
};
template<>
void A<int>::fn(const std::string& s)
{
// this is supposed to be A::fn() specialization for type int
}
int main()
{
A<int> a;
a.fn(""); // ok, invokes the specialized fn()
A<char> ach;
ach.fn(""); // ok, invokes the generic fn()
A<Nullable<int> > an;
an.fn(""); // ok, invokes the generic fn()
return 0;
}
I need to specialize A::fn() for Nullable<>, something like this:
template <typename T>
void A<Nullable<T> >::fn(const std::string& s)
{}
Of course it won't compile. Is there any solution for this?
Thanks
m.
parameter is a template itself.
Suppose this code:
#include <string>
template <typename T>
struct Nullable
{};
template <typename T>
class A
{
public:
void fn(const std::string& s)
{}
};
template<>
void A<int>::fn(const std::string& s)
{
// this is supposed to be A::fn() specialization for type int
}
int main()
{
A<int> a;
a.fn(""); // ok, invokes the specialized fn()
A<char> ach;
ach.fn(""); // ok, invokes the generic fn()
A<Nullable<int> > an;
an.fn(""); // ok, invokes the generic fn()
return 0;
}
I need to specialize A::fn() for Nullable<>, something like this:
template <typename T>
void A<Nullable<T> >::fn(const std::string& s)
{}
Of course it won't compile. Is there any solution for this?
Thanks
m.