Is it possible to write a function as:
void func(uint64_t val) {template <typename T>
void call_with(std::function<void(T)> f, T val) {
f(val);
}
int main() {
auto print = [](int x) { std::cout << x; };
call_with(print, 42);
}}
where a compile time error is generated if it’s called with any other integer type than uint64_t, without modifying my #pragma warnings?
ie:
uint32_t x = 0;
func(x) {…} // Error!
func(uint64_t(x)) {…} // Succes!
Overload the function with a function template. The function template will be a better match for all argument types except
uint64_t. You can define the function template, so that it will create an error if used.With C++11 you can use the following template: