Hi have been thinking that is it possible to have template classes with template functions such that functions only accept certain types. I mean that, if I have a template class
1 2 3 4 5 6 7 8 9 10 11 12 13
template<typename A>
test_class {
public:
template<typename B,class C>
void test_function(B &b, std::vector<C> &c);
};
template<typename A>
template<typename B, class C>
void test_class<A>::test_function(B &b, std::vector<C> &c){
// Do something with real numbers, but this doesn't
// compile with complex numbers
}
where test_function only works with real floating point numbers ( B = double, float or long double ) but it doesn't work with complex numbers. ( B = std::complex<double>, std::complex<float> or std::std::complex<long double> ) However, I might call this test_function somewhere else in the code also with complex numbers and then it should not do anything! I want that this function is compatible with my other functions, classes and so on. That is why I want to do this.. Any help is greatly appreciated!
You could also use the version that doesn't modify the function signature (see foo3 example in the link I sent) - but this doesn't work in my MSVS2010. If your compiler supports default parameters for function template arguments - then go for it.