c++ - Template parameter based on expected return type -


right have this:

int = getval<int>("key1"); double b = getval<double>("key2"); 

where getval() casts , returns value corresponding key. possible turn this:

int = getval("key1"); double b = getval("key2"); 

it's not huge difference in code, i'm wondering if possible. help.

something this:

template <typename t> t getval(const string& key);  // before  class valproxy { private:   valproxy(const string& key) : key_(key) {}   string key_;    friend valproxy getval(const string& key); public:   template <typename t>   operator t() const {     return getval<t>(key_);   } };  valproxy getval(const string& key) {   return valproxy(key); } 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -