]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | # <small>nlohmann::basic_json::</small>operator< |
2 | ||
3 | ```cpp | |
4 | bool operator<(const_reference lhs, const_reference rhs) noexcept; | |
5 | ||
6 | template<typename ScalarType> | |
7 | bool operator<(const_reference lhs, const ScalarType rhs) noexcept; | |
8 | ||
9 | template<typename ScalarType> | |
10 | bool operator<(ScalarType lhs, const const_reference rhs) noexcept; | |
11 | ``` | |
12 | ||
13 | Compares whether one JSON value `lhs` is less than another JSON value `rhs` according to the following rules: | |
14 | ||
15 | - If `lhs` and `rhs` have the same type, the values are compared using the default `<` operator. | |
16 | - Integer and floating-point numbers are automatically converted before comparison | |
17 | - Discarded values a | |
18 | - In case `lhs` and `rhs` have different types, the values are ignored and the order of the types is considered, which | |
19 | is: | |
20 | 1. null | |
21 | 2. boolean | |
22 | 3. number (all types) | |
23 | 4. object | |
24 | 5. array | |
25 | 6. string | |
26 | 7. binary | |
27 | ||
28 | For instance, any boolean value is considered less than any string. | |
29 | ||
30 | ## Template parameters | |
31 | ||
32 | `ScalarType` | |
33 | : a scalar type according to `std::is_scalar<ScalarType>::value` | |
34 | ||
35 | ## Parameters | |
36 | ||
37 | `lhs` (in) | |
38 | : first value to consider | |
39 | ||
40 | `rhs` (in) | |
41 | : second value to consider | |
42 | ||
43 | ## Return value | |
44 | ||
45 | whether `lhs` is less than `rhs` | |
46 | ||
47 | ## Exception safety | |
48 | ||
49 | No-throw guarantee: this function never throws exceptions. | |
50 | ||
51 | ## Complexity | |
52 | ||
53 | Linear. | |
54 | ||
55 | ## Examples | |
56 | ||
57 | ??? example | |
58 | ||
59 | The example demonstrates comparing several JSON types. | |
60 | ||
61 | ```cpp | |
62 | --8<-- "examples/operator__less.cpp" | |
63 | ``` | |
64 | ||
65 | Output: | |
66 | ||
67 | ```json | |
68 | --8<-- "examples/operator__less.output" | |
69 | ``` | |
70 | ||
71 | ## Version history | |
72 | ||
73 | - Added in version 1.0.0. |