'How to limit templated function instantiation to certain type when call site is in the same file as function template definition?
// I only wanted these functions be used for certain types, e.g., say, int and float
template <typename T>
void func() {
}
void another_function() {
func<int>(); // works
func<float>(); // works
func<string>(); // I want this to not compile
}
I think adding explicit instantiation in this file does not work because func and another_function are in the same translational unit. Is there another approach to handle this situation?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
