mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2024-12-27 11:21:02 +08:00
[Language Conformance] Use constexpr restriction in jsoncpp (#1005)
* use constexpr restriction in jsoncpp * remove TODO comment
This commit is contained in:
parent
3550a0a939
commit
7ef0f9fa5b
@ -203,31 +203,33 @@ public:
|
|||||||
static Value const& nullSingleton();
|
static Value const& nullSingleton();
|
||||||
|
|
||||||
/// Minimum signed integer value that can be stored in a Json::Value.
|
/// Minimum signed integer value that can be stored in a Json::Value.
|
||||||
static const LargestInt minLargestInt;
|
static constexpr LargestInt minLargestInt = LargestInt(~(LargestUInt(-1) / 2));
|
||||||
/// Maximum signed integer value that can be stored in a Json::Value.
|
/// Maximum signed integer value that can be stored in a Json::Value.
|
||||||
static const LargestInt maxLargestInt;
|
static constexpr LargestInt maxLargestInt = LargestInt(LargestUInt(-1) / 2);
|
||||||
/// Maximum unsigned integer value that can be stored in a Json::Value.
|
/// Maximum unsigned integer value that can be stored in a Json::Value.
|
||||||
static const LargestUInt maxLargestUInt;
|
static constexpr LargestUInt maxLargestUInt = LargestUInt(-1);
|
||||||
|
|
||||||
/// Minimum signed int value that can be stored in a Json::Value.
|
/// Minimum signed int value that can be stored in a Json::Value.
|
||||||
static const Int minInt;
|
static constexpr Int minInt = Int(~(UInt(-1) / 2));
|
||||||
/// Maximum signed int value that can be stored in a Json::Value.
|
/// Maximum signed int value that can be stored in a Json::Value.
|
||||||
static const Int maxInt;
|
static constexpr Int maxInt = Int(UInt(-1) / 2);
|
||||||
/// Maximum unsigned int value that can be stored in a Json::Value.
|
/// Maximum unsigned int value that can be stored in a Json::Value.
|
||||||
static const UInt maxUInt;
|
static constexpr UInt maxUInt = UInt(-1);
|
||||||
|
|
||||||
#if defined(JSON_HAS_INT64)
|
#if defined(JSON_HAS_INT64)
|
||||||
/// Minimum signed 64 bits int value that can be stored in a Json::Value.
|
/// Minimum signed 64 bits int value that can be stored in a Json::Value.
|
||||||
static const Int64 minInt64;
|
static constexpr Int64 minInt64 = Int64(~(UInt64(-1) / 2));
|
||||||
/// Maximum signed 64 bits int value that can be stored in a Json::Value.
|
/// Maximum signed 64 bits int value that can be stored in a Json::Value.
|
||||||
static const Int64 maxInt64;
|
static constexpr Int64 maxInt64 = Int64(UInt64(-1) / 2);
|
||||||
/// Maximum unsigned 64 bits int value that can be stored in a Json::Value.
|
/// Maximum unsigned 64 bits int value that can be stored in a Json::Value.
|
||||||
static const UInt64 maxUInt64;
|
static constexpr UInt64 maxUInt64 = UInt64(-1);
|
||||||
#endif // defined(JSON_HAS_INT64)
|
#endif // defined(JSON_HAS_INT64)
|
||||||
|
|
||||||
/// Default precision for real value for string representation.
|
/// Default precision for real value for string representation.
|
||||||
static const UInt defaultRealPrecision;
|
static constexpr UInt defaultRealPrecision = 17;
|
||||||
|
// The constant is hard-coded because some compiler have trouble
|
||||||
|
// converting Value::maxUInt64 to a double correctly (AIX/xlC).
|
||||||
|
// Assumes that UInt64 is a 64 bits integer.
|
||||||
|
static constexpr double maxUInt64AsDouble = 18446744073709551615.0;
|
||||||
// Workaround for bug in the NVIDIAs CUDA 9.1 nvcc compiler
|
// Workaround for bug in the NVIDIAs CUDA 9.1 nvcc compiler
|
||||||
// when using gcc and clang backend compilers. CZString
|
// when using gcc and clang backend compilers. CZString
|
||||||
// cannot be defined as private. See issue #486
|
// cannot be defined as private. See issue #486
|
||||||
|
@ -1548,12 +1548,11 @@ bool OurReader::decodeNumber(Token& token, Value& decoded) {
|
|||||||
if (isNegative)
|
if (isNegative)
|
||||||
++current;
|
++current;
|
||||||
|
|
||||||
// TODO(issue #960): Change to constexpr
|
static constexpr auto positive_threshold = Value::maxLargestUInt / 10;
|
||||||
static const auto positive_threshold = Value::maxLargestUInt / 10;
|
static constexpr auto positive_last_digit = Value::maxLargestUInt % 10;
|
||||||
static const auto positive_last_digit = Value::maxLargestUInt % 10;
|
static constexpr auto negative_threshold =
|
||||||
static const auto negative_threshold =
|
|
||||||
Value::LargestUInt(Value::minLargestInt) / 10;
|
Value::LargestUInt(Value::minLargestInt) / 10;
|
||||||
static const auto negative_last_digit =
|
static constexpr auto negative_last_digit =
|
||||||
Value::LargestUInt(Value::minLargestInt) % 10;
|
Value::LargestUInt(Value::minLargestInt) % 10;
|
||||||
|
|
||||||
const auto threshold = isNegative ? negative_threshold : positive_threshold;
|
const auto threshold = isNegative ? negative_threshold : positive_threshold;
|
||||||
|
@ -88,23 +88,6 @@ Value const& Value::null = Value::nullSingleton();
|
|||||||
Value const& Value::nullRef = Value::nullSingleton();
|
Value const& Value::nullRef = Value::nullSingleton();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const Int Value::minInt = Int(~(UInt(-1) / 2));
|
|
||||||
const Int Value::maxInt = Int(UInt(-1) / 2);
|
|
||||||
const UInt Value::maxUInt = UInt(-1);
|
|
||||||
#if defined(JSON_HAS_INT64)
|
|
||||||
const Int64 Value::minInt64 = Int64(~(UInt64(-1) / 2));
|
|
||||||
const Int64 Value::maxInt64 = Int64(UInt64(-1) / 2);
|
|
||||||
const UInt64 Value::maxUInt64 = UInt64(-1);
|
|
||||||
// The constant is hard-coded because some compiler have trouble
|
|
||||||
// converting Value::maxUInt64 to a double correctly (AIX/xlC).
|
|
||||||
// Assumes that UInt64 is a 64 bits integer.
|
|
||||||
static const double maxUInt64AsDouble = 18446744073709551615.0;
|
|
||||||
#endif // defined(JSON_HAS_INT64)
|
|
||||||
const LargestInt Value::minLargestInt = LargestInt(~(LargestUInt(-1) / 2));
|
|
||||||
const LargestInt Value::maxLargestInt = LargestInt(LargestUInt(-1) / 2);
|
|
||||||
const LargestUInt Value::maxLargestUInt = LargestUInt(-1);
|
|
||||||
|
|
||||||
const UInt Value::defaultRealPrecision = 17;
|
|
||||||
|
|
||||||
#if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
|
#if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user