diff options
Diffstat (limited to 'src/univalue/include')
-rw-r--r-- | src/univalue/include/univalue.h | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/univalue/include/univalue.h b/src/univalue/include/univalue.h index 5cb8268472..b665954927 100644 --- a/src/univalue/include/univalue.h +++ b/src/univalue/include/univalue.h @@ -116,19 +116,7 @@ public: const std::vector<std::string>& getKeys() const; const std::vector<UniValue>& getValues() const; template <typename Int> - auto getInt() const - { - static_assert(std::is_integral<Int>::value); - if (typ != VNUM) { - throw std::runtime_error("JSON value is not an integer as expected"); - } - Int result; - const auto [first_nonmatching, error_condition] = std::from_chars(val.data(), val.data() + val.size(), result); - if (first_nonmatching != val.data() + val.size() || error_condition != std::errc{}) { - throw std::runtime_error("JSON integer out of range"); - } - return result; - } + Int getInt() const; bool get_bool() const; const std::string& get_str() const; double get_real() const; @@ -146,6 +134,21 @@ void UniValue::push_backV(It first, It last) values.insert(values.end(), first, last); } +template <typename Int> +Int UniValue::getInt() const +{ + static_assert(std::is_integral<Int>::value); + if (typ != VNUM) { + throw std::runtime_error("JSON value is not an integer as expected"); + } + Int result; + const auto [first_nonmatching, error_condition] = std::from_chars(val.data(), val.data() + val.size(), result); + if (first_nonmatching != val.data() + val.size() || error_condition != std::errc{}) { + throw std::runtime_error("JSON integer out of range"); + } + return result; +} + enum jtokentype { JTOK_ERR = -1, JTOK_NONE = 0, // eof |