加速模板函数编译 我在C++代码中使用了很长的编译时间,在这里我使用了一些来自外部库的模板函数。

加速模板函数编译 我在C++代码中使用了很长的编译时间,在这里我使用了一些来自外部库的模板函数。,c++,templates,precompiled-headers,C++,Templates,Precompiled Headers,例如: //fun.h template <class T> T fun(T in){ ... } //main.cpp #include fun.h class A{...}; int main(){ A a,b; ... b=fun<A>(a); //this line causes the long compilation time, because fun is really complicated ... } //fun.h 模板 T fun(T in)

例如:

//fun.h
template <class T>
T fun(T in){
 ...
}

//main.cpp
#include fun.h
class A{...};
int main(){
A a,b;
...
b=fun<A>(a);  //this line causes the long compilation time, because fun is really complicated
...
}
//fun.h
模板
T fun(T in){
...
}
//main.cpp
#包括乐趣
A类{…};
int main(){
A,b;
...
b=fun(a);//这一行导致编译时间过长,因为fun非常复杂
...
}
我在考虑如何定义新函数

funA := fun<A> 
funA:=fun
在单独的头文件中,并对其进行预编译。因此,每次更改main.cpp时,我都不必构建

fun<A>
有趣
又一次又一次。但是我不知道怎么做。我认为,在课堂上,你可以简单地

typedef class<A> classA;
typedef A类;

在预编译的头文件中,您就完成了。但是如何使用函数呢?

wrap\u fun.h

A funA(A a);
wrap_fun.C

#include "wrap_fun.h"
#include "fun.h"

A funA(A a)
{
    return fun(a);  // Should deduce type automatically.
}

有多少时间是非常长的?代码到底有多复杂?它是否实例化了许多其他模板?在GCC中,您可以尝试使用预编译的头文件。