条款25:考虑写出一个不抛异常的 swap 函数
class template 偏特化
namespace std {
template<typename T>
void swap(T& a, T& b) {
T temp(a);
a = b;
b = temp;
}
}class WidgetImpl {
private:
int a, b, c;
std::vector<double> v; // 可能要复制很长时间;
};
class Widget {
public:
Widget(const Widget& rhs) {
...
*pImpl = *(rhs.pImpl);
}
...
private:
WidgetImpl* pImpl;
};function template 偏特化
Last updated