Add Section::value_or

This commit is contained in:
Vinnie Falco
2017-02-02 11:02:02 -05:00
committed by Edward Hennis
parent 71b42dcec5
commit ce7e83f763

View File

@@ -148,6 +148,17 @@ public:
return boost::lexical_cast<T>(iter->second);
}
/// Returns a value if present, else another value.
template<class T>
T
value_or(std::string const& name, T const& other) const
{
auto const iter = cont().find(name);
if (iter == cont().end())
return other;
return boost::lexical_cast<T>(iter->second);
}
friend
std::ostream&
operator<< (std::ostream&, Section const& section);