I have a class with template Inside this class there is a variable T * Variable; and variable string str; and there is function with part of the code:
if(std::is_same<T, string>::value){
*Variable = str;
return 0;
}
Naturally despite above asignment wont work on different variables due to condition before, compiler moans on compile time. I was thinking about writing conditional template function with two template arguments to put it in place of above asignment:
Assign(Variable, &str);
And before the class:
template <typename T, typename U>
conditional <T, U> void Assign(T* to, U* from){
;
}
conditional <string, string> void Assign(T* to, U* from){
*to = *from;
}
So the compiler would choose specialized one for my needed string. How to formulate this? Can this be formulated just for variable types or do I need a third argument? Or maybe there can be some sort of template condition for just primary code inside function?