I want to specialize following member function:
class foo {
template
T get() const;
};
To other class bar>
You can't partially specialize function templates, sorry but those are the rules. You can do something like:
class foo {
...
};
template
struct getter {
static T get(const foo& some_foo);
};
template
struct getter< std::pair > {
static std::pair get(const foo& some_foo) {
T1 t1 = ...;
T2 t2 = ...;
return std::make_pair(t1, t2);
};
and then call it like
getter >::get(some_foo);
though. You may have to do some messing around with friend
ship or visibility if get
really needed to be a member function.
To elaborate on sbi's suggestion:
class foo {
...
template
T get() const;
};
template
T foo::get() const
{
return getter::get(*this);
/* ^-- specialization happens here */
}
And now you're back to being able to say
std::pair p = some_foo.get >();