Here is the problem:
Header file (part of a library’s API):
template <typename IterType>
void foo(const IterType &begin, const IterType &end);
CPP file:
template <typename IterType>
void my_really_large_implementation_specific_function(const IterType &begin, const IterType &end) {
// ...
}
Is is possible to make foo() call my_really_large_implementation_specific_function() without including my_really_large_implementation_specific_function()‘s code in a header file and without making more than one instance of its template? Maybe using some kind of wrapper iterator class, but I’m not sure how.
If you want your function to be able to operate on arbitrary iterator types then the body needs to appear in the header.
If you need to support only one iterator type then it doesn’t need to be a template and can appear in the source file.