mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Add Section::value_or
This commit is contained in:
committed by
Edward Hennis
parent
71b42dcec5
commit
ce7e83f763
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user