21#include <nlohmann/json.hpp>
30 template<
typename... Ts>
32 using type = std::tuple<Ts...>;
44 template<
class Functor,
typename... Ts>
45 inline bool on_variant_match(
46 const std::string &type_id, Functor &&callback,
const std::variant<Ts...> &var) {
51 if (!matched && type_id == Ts::variant_type_name) {
61 template<
class Functor,
typename... Ts>
62 inline void on_variant_cases(Functor &&callback,
const std::variant<Ts...> &var) {
66 callback(type_tag<Ts>{});
71 template<
typename... Ts>
72 inline void json_deserialize_variant(
73 const nlohmann::json &j,
const std::string &type_id, std::variant<Ts...> &var) {
75 bool matched = on_variant_match(
78 using Talt =
typename decltype(tag)::type;
79 var = std::variant<Ts...>{j.get<Talt>()};
84 std::vector<std::string> available_types;
87 using Talt =
typename decltype(tag)::type;
88 available_types.push_back(std::string(Talt::variant_type_name));
93 "unknown type: {}\navailable types: {}\njson: {}",
This header file contains utility functions related to exception handling in the code.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
namespace for the main framework