Hey guys,
How would I partially specilize a template in a manner as below? Is that even possible?
I have these two functions:
bool node::read(const char *filename) {
ifstream f(filename);
if (!f.good()) return false;
bool success = read(f);
f.close();
return success;
}
bool node::write(const char *filename) {
ofstream f(filename);
if (!f.good()) {
return false;
}
bool success = write(f);
f.close();
return success;
}
And I'd like to create a function like this:
template <typename T>
bool node::read_or_write(const char *filename) {
T f(filename);
if (!f.good()) {
return false;
}
bool success;
if(T == ifstream){
success = write(f);
} else if (T == ofstream){
success = read(f);
}
f.close();
return success;
}
How would I do that?
Thanks in advance,