Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions OptionParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename T>
T get(const std::string& d) const { return (is_set(d)) ? Value((*this)[d]) : T(); }

typedef std::list<std::string>::iterator iterator;
typedef std::list<std::string>::const_iterator const_iterator;
Expand Down
3 changes: 2 additions & 1 deletion testprog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ int main(int argc, char *argv[])
cout << "k: " << options["k"] << endl;
cout << "verbosity: " << options["verbosity"] << endl;
cout << "number: " << (int) options.get("number") << endl;
cout << "int: " << (int) options.get("int") << endl;
// test template getter
cout << "int: " << options.get<int>("int") << endl;
cout << "float: " << (float) options.get("float") << endl;
complex<double> c = 0;
if (options.is_set("complex")) {
Expand Down