Skip to content

Commit 876eb1d

Browse files
committed
use std::numeric_limits for min/max constants
1 parent dd42604 commit 876eb1d

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

include/json/value.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <string>
1313
#include <vector>
1414
#include <map>
15+
#include <limits>
1516

1617
#ifdef JSONCPP_ENABLE_ASSERTS
1718
#define JSONCPP_ASSERT_UNREACHABLE assert(false)
@@ -130,25 +131,25 @@ namespace Json {
130131

131132
static const Value null;
132133
/// Minimum signed integer value that can be stored in a Json::Value.
133-
static const LargestInt minLargestInt;
134+
static constexpr inline auto minLargestInt = std::numeric_limits<LargestInt>::min();
134135
/// Maximum signed integer value that can be stored in a Json::Value.
135-
static const LargestInt maxLargestInt;
136+
static constexpr inline auto maxLargestInt = std::numeric_limits<LargestInt>::max();
136137
/// Maximum unsigned integer value that can be stored in a Json::Value.
137-
static const LargestUInt maxLargestUInt;
138+
static constexpr inline auto maxLargestUInt = std::numeric_limits<LargestUInt>::max();
138139

139140
/// Minimum signed int value that can be stored in a Json::Value.
140-
static const Int minInt;
141+
static constexpr inline auto minInt = std::numeric_limits<Int>::min();
141142
/// Maximum signed int value that can be stored in a Json::Value.
142-
static const Int maxInt;
143+
static constexpr inline auto maxInt = std::numeric_limits<Int>::max();
143144
/// Maximum unsigned int value that can be stored in a Json::Value.
144-
static const UInt maxUInt;
145+
static constexpr inline auto maxUInt = std::numeric_limits<UInt>::max();
145146

146147
/// Minimum signed 64 bits int value that can be stored in a Json::Value.
147-
static const Int64 minInt64;
148+
static constexpr inline auto minInt64 = std::numeric_limits<Int64>::min();
148149
/// Maximum signed 64 bits int value that can be stored in a Json::Value.
149-
static const Int64 maxInt64;
150+
static constexpr inline auto maxInt64 = std::numeric_limits<Int64>::max();
150151
/// Maximum unsigned 64 bits int value that can be stored in a Json::Value.
151-
static const UInt64 maxUInt64;
152+
static constexpr inline auto maxUInt64 = std::numeric_limits<UInt64>::max();
152153

153154
private:
154155
#ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION

src/lib_json/json_value.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,8 @@
2020

2121
namespace Json {
2222

23-
const Value Value::null;
24-
const Int Value::minInt = Int(~(UInt(-1) / 2));
25-
const Int Value::maxInt = Int(UInt(-1) / 2);
26-
const UInt Value::maxUInt = UInt(-1);
27-
const Int64 Value::minInt64 = Int64(~(UInt64(-1) / 2));
28-
const Int64 Value::maxInt64 = Int64(UInt64(-1) / 2);
29-
const UInt64 Value::maxUInt64 = UInt64(-1);
30-
const LargestInt Value::minLargestInt = LargestInt(~(LargestUInt(-1) / 2));
31-
const LargestInt Value::maxLargestInt = LargestInt(LargestUInt(-1) / 2);
32-
const LargestUInt Value::maxLargestUInt = LargestUInt(-1);
33-
3423
/// Unknown size marker
35-
static const unsigned int unknown = (unsigned)-1;
24+
static constexpr auto unknown = std::numeric_limits<unsigned int>::max();
3625

3726
/** Duplicates the specified string value.
3827
* @param value Pointer to the string to duplicate. Must be zero-terminated if

0 commit comments

Comments
 (0)