Mercurial > code
changeset 636:f36b978962fb
json_util: add second template to optional
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 26 Mar 2018 13:56:05 +0200 |
parents | 002c13ee0021 |
children | 89c1d2bd33eb |
files | cpp/json_util/json_util.hpp |
diffstat | 1 files changed, 3 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/cpp/json_util/json_util.hpp Mon Mar 26 13:26:31 2018 +0200 +++ b/cpp/json_util/json_util.hpp Mon Mar 26 13:56:05 2018 +0200 @@ -302,15 +302,15 @@ * \param def the default value if property is undefined * \return the value, boost::none or def */ - template <typename Type> - inline boost::optional<Type> optional(const std::string& key, Type&& def) const noexcept + template <typename Type, typename DefaultValue> + inline boost::optional<Type> optional(const std::string& key, DefaultValue&& def) const noexcept { static_assert(parser_type_traits<Type>::value, "type not supported"); const auto it = json_.find(key); if (it == json_.end()) - return def; + return boost::optional<Type>(std::forward<DefaultValue>(def)); return parser_type_traits<Type>::get(*it); }