this variant is better than strict_si_cast(const char*), because:
* we can just pass std::string to it, as std::string_view can be
constructed from a std::string implicitly
* strict_si_cast(std::string_view, ..) is the underlying
implementation of strict_si_cast(const char*,..), so less
indirection helps with the readability.
Signed-off-by: Kefu Chai <kchai@redhat.com>
max: 32_M
validator: |
[](std::string *value, std::string *error_message) {
- uint64_t f = strict_si_cast<uint64_t>(value->c_str(), error_message);
+ uint64_t f = strict_si_cast<uint64_t>(*value, error_message);
if (!error_message->empty()) {
return -EINVAL;
} else if (!isp2(f)) {
{
return strict_si_cast<uint64_t>(str, err);
}
-
-template<typename T>
-T strict_si_cast(const char *str, std::string *err)
-{
- return strict_si_cast<T>(std::string_view(str), err);
-}
-
-template int strict_si_cast<int>(const char *str, std::string *err);
-template long strict_si_cast<long>(const char *str, std::string *err);
-template long long strict_si_cast<long long>(const char *str, std::string *err);
-template uint64_t strict_si_cast<uint64_t>(const char *str, std::string *err);
-template uint32_t strict_si_cast<uint32_t>(const char *str, std::string *err);
uint64_t strict_sistrtoll(const char *str, std::string *err);
template<typename T>
-T strict_si_cast(const char *str, std::string *err);
+T strict_si_cast(std::string_view str, std::string *err);
/* On enter buf points to the end of the buffer, e.g. where the least
* significant digit of the input number will be printed. Returns pointer to