【C++ 小问答】1:模板实例化

问 以下 foo 函数模板被实例化多少次? 1template <typename T> 2void foo(T f) {} 3 4struct Bar { 5 void operator()(bool x) {} 6}; 7 8void f1(bool x) {} 9 10void f2(bool x) {} 11 12int main() { 13 foo(f1); 14 foo(Bar()); 15 foo(f2); 16 foo([](bool x){}); 17 foo([](bool x){}); 18} 答 使用 C++ Insights 生成该代码的编译器视角: 1template …