I want to specialize following member function:
class foo {
template
T get() const;
};
To other class bar>
You need to overload your member function for pair, like in
template std::pair foo::get()
In the general case you will need to be able to disambiguate between the various overloads. In the case disambiguation is easy because pair is templated on 2 types while the original member was templated on T only.
If instead you needed a specialization for, e.g., std::vector, that is for a container with a single parameter template, you have to be careful since given it can be confusing for the compiler to understand if you wish to instantiate the template specialization where the template T is std::vector or the specialization for the overload,
template std:: foo::get() const
Your proposed syntax cannot work since you are completely specializing the member function,
template <>
,
but you are leaving out two unspecified types, T1 and T2.