我有这段代码,输出如下:
链接到以下示例 https://godbolt.org/z/z8Pn9GsTv
template <typename T>
struct A1 {
A1() {
std::cout << "construction of a1" << std::endl;
}
~A1() {
std::cout << "destruction of a1" << std::endl;
}
~A1() requires (std::is_same_v<T,int>) {
std::cout << "it is an int" << std::endl;
}
};
int main() {
A1 <int>a;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
construction of a1
destruction of a1
Run Code Online (Sandbox Code Playgroud)
但交换析构函数的位置会给出其他结果:
代码链接 https://godbolt.org/z/vxj7dPqaj
template <typename T>
struct A1 {
A1() {
std::cout << "construction of a1" << std::endl;
}
~A1() requires (std::is_same_v<T,int>) …Run Code Online (Sandbox Code Playgroud)