Is it possible to declare that a symbol is an explicit instantiation of a function template, without defining the function template first?
It would express to the compiler that there exists a function template in another translation unit that is instantiated somewhere, and we want to call the instantiated function.
// declaration of instantiation, perhaps it would look like one of these:
// template<typename> void foo(int);
// template<typename> void foo<int>(int);
void bar(int i) {
// definition of function unknown to caller, it shouldn't matter
foo(i);
// either that or this perhaps:
foo<int>(i);
}
Is there a technical reason this can't be done or is it just for lack of syntax? Is there a reason that it's not possible to provide sufficient information in a declaration to generate calls to an instantiated function template?
There is no Y behind this X. This question is meant literally. It's an abstract question about the C++ language. I could provide an example that doesn't compile but that would just be a distraction.
The question is also not about specialization per se. Whether the template was specialized shouldn't matter. This question is only concerned with declaring that a template exists and that it was instantiated.
Related question: How do I explicitly instantiate a template function? - however that does not solve this problem, as it requires the full template definition to be visible.