Explicit instantiation declaration of header only template(extern template)

前端 未结 1 1712
南旧
南旧 2021-02-06 00:57

I am trying to speed up the compile time of the GLM(OpenGL Mathematics). GLM makes heavy usages of C++ templates.

This is what I have tried so far.

math.         


        
相关标签:
1条回答
  • 2021-02-06 01:43

    Your math.h still causes users to include <glm\glm.hpp>
    That's the thing you want to avoid to speed things up. To speed things up, make your own class whose implementation (inside math.cpp) might use glm.hpp, but the users of that class do not need to include glm.hpp themselves.

    This is an example left to the student, but you want something like:

    math.h
    struct vec3{ double x1,x2,x3};
    vec3 plus(const vec3& a, const vec3& b);

    Then when a.cpp includes math.h, it provides the functions you need, but does not make all your compilation units include glm.hpp.

    0 讨论(0)
提交回复
热议问题