lundi 17 juillet 2023

Can function templates slow compilation

I have a class with a function template.

class Foo {
 public:
  void Foo_fn1();

  template <typename Closure>
  void Foo_util (Closure&& closure) {
    Foo_fn1();
    std::forward<Closure>(closure());
  }

};

The above is part of a .h file that has been included at least 10k times in the code base. My question is the following:

Can such usage of templates slow down compilation? Would it be better to write it in a util class with the following signature:

  template <typename Closure>
  void Foo_util (Foo foo, Closure&& closure) {
    foo.Foo_fn1();
    std::forward<Closure>(closure());
  }

Why or Why not? Any documentation explaining the above would be helpful.

Aucun commentaire:

Enregistrer un commentaire