• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# basic_json::is_number
2
3```cpp
4constexpr bool is_number() const noexcept;
5```
6
7This function returns `#!cpp true` if and only if the JSON value is a number. This includes both integer (signed and
8unsigned) and floating-point values.
9
10## Return value
11
12`#!cpp true` if type is number (regardless whether integer, unsigned integer or floating-type), `#!cpp false` otherwise.
13
14## Exception safety
15
16No-throw guarantee: this member function never throws exceptions.
17
18## Complexity
19
20Constant.
21
22## Possible implementation
23
24```cpp
25constexpr bool is_number() const noexcept
26{
27    return is_number_integer() || is_number_float();
28}
29```
30
31## Example
32
33??? example
34
35    The following code exemplifies `is_number()` for all JSON types.
36
37    ```cpp
38    --8<-- "examples/is_number.cpp"
39    ```
40
41    Output:
42
43    ```json
44    --8<-- "examples/is_number.output"
45    ```
46
47## Version history
48
49- Added in version 1.0.0.
50- Extended to also return `#!cpp true` for unsigned integers in 2.0.0.
51