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
Post a Comment