I am wrapping a library into my class design. I would like to call a template method with unsigned int non-type parameter provided in the library in my class constructor.
#include <iostream>
#include <bar.h> // template header in here
class foo {
foo(unsigned num) {
BAR<num>(); // a template method BAR inside "bar.h"
}
};
When I tries to play around with this it seems that the non-type parameter is a constexpr. So the above code will generate error indicating that there is const error inside the function call.
So I decide to make the foo class a class template and pass this unsigned non-type parameter in foo's template argument parameter.
#include <iostream>
#include <bar.h> // template header in here
template <unsigned num>
class foo {
foo() {
BAR<num>(); // a template method BAR inside "bar.h"
}
};
This seems to be working well. However, I would like to separate the header and source file into separate .hpp/.cpp files. According to this thread, if I want to place template implementation inside .cpp source file, I have to explicitly instantiate all possible template argument at the end of .cpp file. For non-type parameter like unsigned integer, does that mean I have to instantiate thousands of possible unsigned int number to make the template available to all unsigned number object? Thanks for the help.