Skip to content
Snippets Groups Projects
Commit 82929fbc authored by Rainer Kartmann's avatar Rainer Kartmann
Browse files

Add simox::json::get_to_if_exists()

parent a7b75971
No related branches found
No related tags found
No related merge requests found
#pragma once
#include <optional>
#include <string>
#include <vector>
#include "json.h"
......@@ -26,4 +28,21 @@ namespace simox::json
return at_any_key(j, keys).get<T>();
}
template <class ValueT, class DefaultT = ValueT>
void get_to_if_exists(const json& j,
const std::string& key,
ValueT& dest,
const DefaultT& default_ = ValueT{})
{
if (j.count(key))
{
j.at(key).get_to(dest);
}
else
{
dest = default_;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment