From 19d257758202b9d9935c3469394ca4c82c584f6a Mon Sep 17 00:00:00 2001 From: Dmitri Lapin Date: Thu, 16 Jun 2016 18:54:55 +0300 Subject: [PATCH 1/3] Added template function to obtain values without explicit cast --- OptionParser.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/OptionParser.h b/OptionParser.h index ccafbc5..fb80b93 100644 --- a/OptionParser.h +++ b/OptionParser.h @@ -61,6 +61,8 @@ class Values { bool is_set_by_user(const std::string& d) const { return _userSet.find(d) != _userSet.end(); } void is_set_by_user(const std::string& d, bool yes); Value get(const std::string& d) const { return (is_set(d)) ? Value((*this)[d]) : Value(); } + template + T get(const std::string& d) const { return (is_set(d)) ? Value((*this)[d]) : T(); } typedef std::list::iterator iterator; typedef std::list::const_iterator const_iterator; From 9dd9b08e45cb103c9ed3af6b24d923c4908dd515 Mon Sep 17 00:00:00 2001 From: Dmitri Lapin Date: Thu, 16 Jun 2016 19:08:51 +0300 Subject: [PATCH 2/3] Added test case for template version of get --- testprog.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/testprog.cpp b/testprog.cpp index ac68f1f..c281e53 100644 --- a/testprog.cpp +++ b/testprog.cpp @@ -143,6 +143,10 @@ int main(int argc, char *argv[]) cout << "number: " << (int) options.get("number") << endl; cout << "int: " << (int) options.get("int") << endl; cout << "float: " << (float) options.get("float") << endl; + // test template getters + cout << "number