diff --git a/src/strings_internal.h b/src/strings_internal.h index d4f52c00e4..e56f2b8cea 100644 --- a/src/strings_internal.h +++ b/src/strings_internal.h @@ -91,10 +91,13 @@ public: template T GetNextParameter() { + struct visitor { + uint64_t operator()(const uint64_t &arg) { return arg; } + uint64_t operator()(const std::string &) { throw std::out_of_range("Attempt to read string parameter as integer"); } + }; + const auto ¶m = GetNextParameterReference(); - const uint64_t *data = std::get_if(¶m.data); - if (data != nullptr) return static_cast(*data); - throw std::out_of_range("Attempt to read string parameter as integer"); + return static_cast(std::visit(visitor{}, param.data)); } /** @@ -105,10 +108,13 @@ public: */ const char *GetNextParameterString() { + struct visitor { + const char *operator()(const uint64_t &) { throw std::out_of_range("Attempt to read integer parameter as string"); } + const char *operator()(const std::string &arg) { return arg.c_str(); } + }; + const auto ¶m = GetNextParameterReference(); - const std::string *data = std::get_if(¶m.data); - if (data != nullptr) return data->c_str(); - throw std::out_of_range("Attempt to read integer parameter as string"); + return std::visit(visitor{}, param.data); } /**