1
0
Fork 0

Codechange: Detemplatise uint64_t version of GetNextParameters().

This ensures the visitor is not duplicated for the different types pass to GetNextParamters<T>(), which now is only concerned with casting the result.
pull/13488/head
Peter Nelson 2024-12-03 23:02:43 +00:00
parent c3643e3ee0
commit 37119ceb96
No known key found for this signature in database
GPG Key ID: 8EF8F0A467DF75ED
1 changed files with 16 additions and 4 deletions

View File

@ -80,16 +80,28 @@ public:
* will be read.
* @return The next parameter's value.
*/
template <typename T>
T GetNextParameter()
uint64_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 &param = GetNextParameterReference();
return static_cast<T>(std::visit(visitor{}, param.data));
const auto &param = this->GetNextParameterReference();
return std::visit(visitor{}, param.data);
}
/**
* Get the next parameter from our parameters.
* This updates the offset, so the next time this is called the next parameter
* will be read.
* @tparam T The return type of the parameter.
* @return The next parameter's value.
*/
template <typename T>
T GetNextParameter()
{
return static_cast<T>(this->GetNextParameter());
}
/**