是否可以将非模板逻辑移至标头之外?
我已将半边数据结构作为模板库实现。这样做的原因是,我不得不将此库从GLM移植到eigen,然后我不得不将其扩展到任意维度上的工作,但只有3D。
结果,我发誓从不只是在这里和那里乏味地更改类型,只是要有半边缘。
但是,尽管我的半边缘按预期运行并执行,但它是一个很大的标头,以至于我在任何包含它的文件上都花费了30%左右的编译时间。
令人沮丧的是,也许图书馆所做的事情的80%完全不可知几何数据。
一般概述将像
template<typename Data>
class HalfMesh
{
vector<Data> data;
vector<HalfEdge> verts;
vector<HalfEdge> edges;
vector<Face> faces;
void SomeMethod(){/* uses only verts, edges, and faces */}
};
在这种情况下一样vert,边,面,面孔
都是非模板类别的类别,而该结构正在执行的80%涉及这三个类,而不是data
。
我想减少编译时间,因此理想情况下,我想将一些成员方法向下移动到CPP文件中,然后从标题中移出。
是否有一些语法要告诉C ++“对于任何模板,所有这些功能都是相同的,链接到CPP文件,让我将实现从标题中移出”?
I have implemented a half edge data structure as a template library. The reason for this is, I have had to port this library from glm to eigen, and then I had to extend it to work on arbitrary dimensions, but just 3D.
As a result I vowed to never just tediously change types here and there just to have a half edge.
However, although my half edge runs and performs as expected, it's such a large header that it is taking 30% or so of my compile times on any file that includes it.
What is frustrating is, maybe 80% of what the library is doing is completely agnostic to what the geometric data is.
The general overview would be something like
template<typename Data>
class HalfMesh
{
vector<Data> data;
vector<HalfEdge> verts;
vector<HalfEdge> edges;
vector<Face> faces;
void SomeMethod(){/* uses only verts, edges, and faces */}
};
In this scenario verts, edges, faces
are all non templated classes and 80% of what this structure is doing involves those 3 classes and not Data
.
I want to reduce my compile times, so ideally I want to move some member methods down into a cpp file and out of the header.
Is there some syntax to tell c++ "all this functions are the same for any template, link to a cpp file and let me move the implementation out of the header"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建一个非模板基类,并将所有不依赖于模板参数的内容移至其中。其功能可以在.cpp文件中实现。
Create a non-template base class, and move everything that doesn't depend on template parameters to it. Its functions can be implemented in a .cpp file.
“ PIMPL”技术是协助减少汇编时间的替代方法。
https://en.cppreference.com/w/cpp/langueage/pimpl
The technique 'pimpl' is an alternate method for assisting in the reduction of compilation time.
https://en.cppreference.com/w/cpp/language/pimpl