I was provided with several classes, and only one of them uses the .open method, and the rest use .load
Is there a smarter way to achieve something like the (simplified) code below? Or should I change the definitions of the above classes?
template <class element> bool load (element & el, std::string file) { bool status; if (std::is_same <element, some_special_class>::value) { status = el.open (file); } else { status = el.load (file); }
It seems a little better
void lotOfCode (bool status) { if (status) {
than that
template <class element> bool load (element & el, std::string file) { if (el.load (file)) { // some code return true; // loaded } // more code return false; } bool load (some_special_class & el, std::string file) { if (el.open (file)) { // some code return true; // loaded } // more code return false; }
but is it enough?
source share