1
0
Fork 0

Codechange: Detemplatise uint64_t version of GetNextParameters(). (#13488)

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/13472/head
Peter Nelson 2025-02-07 18:54:40 +00:00 committed by GitHub
parent 9189c3ab6f
commit 52094c1fc1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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());
}
/**