I'm trying to implement a generic configuration file parser and I'm wondering how to write a method in my class that is able to determine its return type, based on the type of an input parameter. Here's what I mean:
class Config
{
...
template <typename T>
T GetData (const std::string &key, const T &defaultValue) const;
...
}
In order to call the above method, I have to use something like this:
some_type data = Config::GetData<some_type>("some_key", defaultValue);
How can I get rid of the redundant specification? I saw that boost::property_tree::ptree::get() is able to do this trick, but the implementation is rather complicated and I wasn't able to decipher this complex declaration:
template<class Type, class Translator>
typename boost::enable_if<detail::is_translator<Translator>, Type>::type
get(const path_type &path, Translator tr) const;
If possible, I would like to do this, without creating a dependency on boost in the code that will use my Config class.
PS: I'm a n00b when it comes to C++ templates :(