* Allow the same type for number_integer_t and number_unsigned_t basic_json did not compile with NumberUnsignedType == NumberIntegerType because overloads on both types collided. Such a basic_json now stores every integer as number_integer: the colliding overloads take a placeholder type, unsigned C++ integers are converted to number_integer_t, and value_t::number_unsigned maps to number_integer. Also fixes two problems this configuration would hit: the unsigned integer parser accepted values that wrap around to negative numbers, and dump() overflowed when computing the absolute value of the minimum. A repeated NumberFloatType gets a static_assert. Refs #2573 Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Use json::with_integers_t in the test and the docs Signed-off-by: Niels Lohmann <mail@nlohmann.me> * ✅ skip patch test on GCC 5 to avoid internal compiler error Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Fix CI: name the unsigned overload type through template parameters basic_json used number_unsigned_overload_t<basic_json> while the class was still incomplete. MSVC rejected it as a recursive alias declaration and GCC 4.9, 5 and 7 crashed with an internal compiler error. basic_json now uses number_unsigned_overload_type<NumberIntegerType, NumberUnsignedType>, which also makes the GCC 5 workaround in the patch test unnecessary. Infer reported a null dereference for the number_unsigned case in from_json, which cannot happen for a basic_json whose number_unsigned_t is number_integer_t; assert it. Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Address review: conjunction/negation trait, astyle-friendly alias, docs table order Signed-off-by: Niels Lohmann <mail@nlohmann.me> --------- Signed-off-by: Niels Lohmann <mail@nlohmann.me>
1.2 KiB
1.2 KiB
nlohmann::basic_json::is_number_unsigned
constexpr bool is_number_unsigned() const noexcept;
This function returns #!cpp true if and only if the JSON value is an unsigned integer number. This excludes
floating-point and signed integer values.
If number_unsigned_t is the same type as number_integer_t, every
integer is stored as number_integer_t, and this function always returns #!cpp false.
Return value
#!cpp true if type is an unsigned integer number, #!cpp false otherwise.
Exception safety
No-throw guarantee: this member function never throws exceptions.
Complexity
Constant.
Examples
??? example
The following code exemplifies `is_number_unsigned()` for all JSON types.
```cpp
--8<-- "examples/is_number_unsigned.cpp"
```
Output:
```json
--8<-- "examples/is_number_unsigned.output"
```
See also
- is_number() check if the value is a number
- is_number_integer() check if the value is an integer or unsigned integer number
- is_number_float() check if the value is a floating-point number
Version history
- Added in version 2.0.0.