是否有理由在 header 中保留完全专业化的模板?

Are there reasons for keeping fully specialized template in the header?

如果我有一个完全专业化的模板函数,例如:

// This stay in the header
template<typename X>
void foo(x b);

// This goes into the source file - any drawbacks?
template<>
void foo(Bar b) {
  ...
}

是否有理由将其保留在 header 而不是源文件中?我想将它们保留在源文件中,以减少编译时间(这些专用函数可能会变得非常大,而且它们会在 header 中引入很多依赖项),但我想知道是否存在是将它们放入源文件的任何权衡。

对于完全专用的模板,声明仍然应该在 header 中(这样编译器就知道它不使用主模板):

template<> void foo(Bar b);

但定义可以放在 cpp 文件中(或保留在 header 中):

template<>
void foo(Bar b) {
  //...
}