Is it preferred to place the body of a template function in the header file or its corresponding cpp file and why?
I have some code that I slightly modified, thanks to the answer written by Nikos Athanasiou found on this thread and is seen below. Currently, I have all the below code in a single header file.
I have read the threads out there explaining how you can have the template function definition in the header file and template function body in the cpp file, but I am wondering which would be considered correct. Are there any performance pros and cons to either option?
typedef std::chrono::duration<float> fsec;
template<typename F, typename... Args>
float ftime_fsec(F func, Args&&... args){
auto t1 = std::chrono::high_resolution_clock::now();
func(std::forward<Args>(args)...);
return std::chrono::duration_cast<fsec>
(std::chrono::high_resolution_clock::now() - t1).count();
}