This commit is contained in:
nlohmann committed 2026-10-03 07:03:52 +00:00
1 parent a410b4f40f
commit ba443db2af
22 files changed
+127 -78

No files matched your search

+10 -4
View File
@@ -5,17 +5,17 @@
bool operator==(const_reference lhs, const_reference rhs) noexcept; // (1) bool operator==(const_reference lhs, const_reference rhs) noexcept; // (1)
template<typename ScalarType> template<typename ScalarType>
bool operator==(const_reference lhs, const ScalarType rhs) noexcept; // (2) bool operator==(const_reference lhs, const ScalarType rhs) noexcept(/* see below */); // (2)
template<typename ScalarType> template<typename ScalarType>
bool operator==(ScalarType lhs, const const_reference rhs) noexcept; // (2) bool operator==(ScalarType lhs, const const_reference rhs) noexcept(/* see below */); // (2)
// since C++20 // since C++20
class basic_json { class basic_json {
bool operator==(const_reference rhs) const noexcept; // (1) bool operator==(const_reference rhs) const noexcept; // (1)
template<typename ScalarType> template<typename ScalarType>
bool operator==(ScalarType rhs) const noexcept; // (2) bool operator==(ScalarType rhs) const noexcept(/* see below */); // (2)
}; };
``` ```
@@ -46,7 +46,12 @@ whether the values `lhs`/`*this` and `rhs` are equal
## Exception safety ## Exception safety
No-throw guarantee: this function never throws exceptions. 1. No-throw guarantee: this function never throws exceptions.
2. No-throw guarantee if converting the scalar to a JSON value cannot throw, as for numbers, Booleans, and
`#!cpp nullptr`; the function is `#!cpp noexcept` exactly in that case. Otherwise, it throws what the conversion
throws, for example `std::bad_alloc` when converting a string, or
[`out_of_range.410`](../../home/exceptions.md#jsonexceptionout_of_range410) for an enum value not mapped by
[`NLOHMANN_JSON_SERIALIZE_ENUM_STRICT`](../macros/nlohmann_json_serialize_enum_strict.md).
## Complexity ## Complexity
@@ -171,3 +176,4 @@ Linear.
1. Added in version 1.0.0. Added C++20 member functions in version 3.11.0. 1. Added in version 1.0.0. Added C++20 member functions in version 3.11.0.
2. Added in version 1.0.0. Added C++20 member functions in version 3.11.0. 2. Added in version 1.0.0. Added C++20 member functions in version 3.11.0.
Made conditionally `#!cpp noexcept` in version 3.13.0; before, a throwing conversion called `std::terminate`.
+5 -5
View File
@@ -2,19 +2,19 @@
<span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>==</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (1)</span> <span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>==</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (1)</span>
<span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span> <span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span>
<span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>==</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>ScalarType</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (2)</span> <span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>==</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>ScalarType</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>(</span><span class=cm>/* see below */</span><span class=p>);</span><span class=w> </span><span class=c1>// (2)</span>
<span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span> <span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span>
<span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>==</span><span class=p>(</span><span class=n>ScalarType</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (2)</span> <span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>==</span><span class=p>(</span><span class=n>ScalarType</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>(</span><span class=cm>/* see below */</span><span class=p>);</span><span class=w> </span><span class=c1>// (2)</span>
<span class=c1>// since C++20</span> <span class=c1>// since C++20</span>
<span class=k>class</span><span class=w> </span><span class=nc>basic_json</span><span class=w> </span><span class=p>{</span> <span class=k>class</span><span class=w> </span><span class=nc>basic_json</span><span class=w> </span><span class=p>{</span>
<span class=w> </span><span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>==</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (1)</span> <span class=w> </span><span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>==</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (1)</span>
<span class=w> </span><span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span> <span class=w> </span><span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span>
<span class=w> </span><span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>==</span><span class=p>(</span><span class=n>ScalarType</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (2)</span> <span class=w> </span><span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>==</span><span class=p>(</span><span class=n>ScalarType</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=k>noexcept</span><span class=p>(</span><span class=cm>/* see below */</span><span class=p>);</span><span class=w> </span><span class=c1>// (2)</span>
<span class=p>};</span> <span class=p>};</span>
</code></pre></div> <ol> <li> <p>Compares two <abbr title="JavaScript Object Notation">JSON</abbr> values for equality according to the following rules:</p> <ul> <li>Two <abbr title="JavaScript Object Notation">JSON</abbr> values are equal if (1) neither value is discarded, and (2) they are of the same type and their stored values are the same according to their respective <code>operator==</code>.</li> <li>Integer and floating-point numbers are automatically converted before comparison.</li> </ul> </li> <li> <p>Compares a <abbr title="JavaScript Object Notation">JSON</abbr> value and a scalar or a scalar and a <abbr title="JavaScript Object Notation">JSON</abbr> value for equality by converting the scalar to a <abbr title="JavaScript Object Notation">JSON</abbr> value and comparing both <abbr title="JavaScript Object Notation">JSON</abbr> values according to 1.</p> </li> </ol> <h2 id=template-parameters>Template parameters<a class=headerlink href=#template-parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>ScalarType</code></dt> <dd>a scalar type according to <code>std::is_scalar&lt;ScalarType&gt;::value</code></dd> </dl> <h2 id=parameters>Parameters<a class=headerlink href=#parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>lhs</code> (in)</dt> <dd>first value to consider </dd> <dt><code>rhs</code> (in)</dt> <dd>second value to consider </dd> </dl> <h2 id=return-value>Return value<a class=headerlink href=#return-value title="Permanent link">&para;</a></h2> <p>whether the values <code>lhs</code>/<code>*this</code> and <code>rhs</code> are equal</p> <h2 id=exception-safety>Exception safety<a class=headerlink href=#exception-safety title="Permanent link">&para;</a></h2> <p>No-throw guarantee: this function never throws exceptions.</p> <h2 id=complexity>Complexity<a class=headerlink href=#complexity title="Permanent link">&para;</a></h2> <p>Linear.</p> <h2 id=notes>Notes<a class=headerlink href=#notes title="Permanent link">&para;</a></h2> <div class="admonition note"> <p class=admonition-title>Comparing special values</p> <ul> <li><code>NaN</code> values are unordered within the domain of numbers. The following comparisons all yield <code class=highlight><span class=nb>false</span></code>:<ol> <li>Comparing a <code>NaN</code> with itself.</li> <li>Comparing a <code>NaN</code> with another <code>NaN</code>.</li> <li>Comparing a <code>NaN</code> and any other number.</li> </ol> </li> <li><abbr title="JavaScript Object Notation">JSON</abbr> <code class=highlight><span class=n>null</span></code> values are all equal.</li> <li>Discarded values never compare equal to themselves.</li> </ul> </div> <div class="admonition note"> <p class=admonition-title>Comparing floating-point numbers</p> <p>Floating-point numbers inside <abbr title="JavaScript Object Notation">JSON</abbr> values numbers are compared with <code>json::number_float_t::operator==</code> which is <code>double::operator==</code> by default. To compare floating-point while respecting an epsilon, an alternative <a href="https://github.com/mariokonrad/marnav/blob/master/include/marnav/math/floatingpoint.hpp#L34-#L39">comparison function</a> could be used, for instance</p> <div class=highlight><pre><span></span><code><span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>T</span><span class=p>,</span><span class=w> </span><span class=k>typename</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=k>typename</span><span class=w> </span><span class=nc>std</span><span class=o>::</span><span class=n>enable_if</span><span class=o>&lt;</span><span class=n>std</span><span class=o>::</span><span class=n>is_floating_point</span><span class=o>&lt;</span><span class=n>T</span><span class=o>&gt;::</span><span class=n>value</span><span class=p>,</span><span class=w> </span><span class=n>T</span><span class=o>&gt;::</span><span class=n>type</span><span class=o>&gt;</span> </code></pre></div> <ol> <li> <p>Compares two <abbr title="JavaScript Object Notation">JSON</abbr> values for equality according to the following rules:</p> <ul> <li>Two <abbr title="JavaScript Object Notation">JSON</abbr> values are equal if (1) neither value is discarded, and (2) they are of the same type and their stored values are the same according to their respective <code>operator==</code>.</li> <li>Integer and floating-point numbers are automatically converted before comparison.</li> </ul> </li> <li> <p>Compares a <abbr title="JavaScript Object Notation">JSON</abbr> value and a scalar or a scalar and a <abbr title="JavaScript Object Notation">JSON</abbr> value for equality by converting the scalar to a <abbr title="JavaScript Object Notation">JSON</abbr> value and comparing both <abbr title="JavaScript Object Notation">JSON</abbr> values according to 1.</p> </li> </ol> <h2 id=template-parameters>Template parameters<a class=headerlink href=#template-parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>ScalarType</code></dt> <dd>a scalar type according to <code>std::is_scalar&lt;ScalarType&gt;::value</code></dd> </dl> <h2 id=parameters>Parameters<a class=headerlink href=#parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>lhs</code> (in)</dt> <dd>first value to consider </dd> <dt><code>rhs</code> (in)</dt> <dd>second value to consider </dd> </dl> <h2 id=return-value>Return value<a class=headerlink href=#return-value title="Permanent link">&para;</a></h2> <p>whether the values <code>lhs</code>/<code>*this</code> and <code>rhs</code> are equal</p> <h2 id=exception-safety>Exception safety<a class=headerlink href=#exception-safety title="Permanent link">&para;</a></h2> <ol> <li>No-throw guarantee: this function never throws exceptions.</li> <li>No-throw guarantee if converting the scalar to a <abbr title="JavaScript Object Notation">JSON</abbr> value cannot throw, as for numbers, Booleans, and <code class=highlight><span class=nb>nullptr</span></code>; the function is <code class=highlight><span class=k>noexcept</span></code> exactly in that case. Otherwise, it throws what the conversion throws, for example <code>std::bad_alloc</code> when converting a string, or <a href=../../../home/exceptions/#jsonexceptionout_of_range410><code>out_of_range.410</code></a> for an enum value not mapped by <a href=../../macros/nlohmann_json_serialize_enum_strict/ ><code>NLOHMANN_JSON_SERIALIZE_ENUM_STRICT</code></a>.</li> </ol> <h2 id=complexity>Complexity<a class=headerlink href=#complexity title="Permanent link">&para;</a></h2> <p>Linear.</p> <h2 id=notes>Notes<a class=headerlink href=#notes title="Permanent link">&para;</a></h2> <div class="admonition note"> <p class=admonition-title>Comparing special values</p> <ul> <li><code>NaN</code> values are unordered within the domain of numbers. The following comparisons all yield <code class=highlight><span class=nb>false</span></code>:<ol> <li>Comparing a <code>NaN</code> with itself.</li> <li>Comparing a <code>NaN</code> with another <code>NaN</code>.</li> <li>Comparing a <code>NaN</code> and any other number.</li> </ol> </li> <li><abbr title="JavaScript Object Notation">JSON</abbr> <code class=highlight><span class=n>null</span></code> values are all equal.</li> <li>Discarded values never compare equal to themselves.</li> </ul> </div> <div class="admonition note"> <p class=admonition-title>Comparing floating-point numbers</p> <p>Floating-point numbers inside <abbr title="JavaScript Object Notation">JSON</abbr> values numbers are compared with <code>json::number_float_t::operator==</code> which is <code>double::operator==</code> by default. To compare floating-point while respecting an epsilon, an alternative <a href="https://github.com/mariokonrad/marnav/blob/master/include/marnav/math/floatingpoint.hpp#L34-#L39">comparison function</a> could be used, for instance</p> <div class=highlight><pre><span></span><code><span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>T</span><span class=p>,</span><span class=w> </span><span class=k>typename</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=k>typename</span><span class=w> </span><span class=nc>std</span><span class=o>::</span><span class=n>enable_if</span><span class=o>&lt;</span><span class=n>std</span><span class=o>::</span><span class=n>is_floating_point</span><span class=o>&lt;</span><span class=n>T</span><span class=o>&gt;::</span><span class=n>value</span><span class=p>,</span><span class=w> </span><span class=n>T</span><span class=o>&gt;::</span><span class=n>type</span><span class=o>&gt;</span>
<span class=kr>inline</span><span class=w> </span><span class=kt>bool</span><span class=w> </span><span class=n>is_same</span><span class=p>(</span><span class=n>T</span><span class=w> </span><span class=n>a</span><span class=p>,</span><span class=w> </span><span class=n>T</span><span class=w> </span><span class=n>b</span><span class=p>,</span><span class=w> </span><span class=n>T</span><span class=w> </span><span class=n>epsilon</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=n>std</span><span class=o>::</span><span class=n>numeric_limits</span><span class=o>&lt;</span><span class=n>T</span><span class=o>&gt;::</span><span class=n>epsilon</span><span class=p>())</span><span class=w> </span><span class=k>noexcept</span> <span class=kr>inline</span><span class=w> </span><span class=kt>bool</span><span class=w> </span><span class=n>is_same</span><span class=p>(</span><span class=n>T</span><span class=w> </span><span class=n>a</span><span class=p>,</span><span class=w> </span><span class=n>T</span><span class=w> </span><span class=n>b</span><span class=p>,</span><span class=w> </span><span class=n>T</span><span class=w> </span><span class=n>epsilon</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=n>std</span><span class=o>::</span><span class=n>numeric_limits</span><span class=o>&lt;</span><span class=n>T</span><span class=o>&gt;::</span><span class=n>epsilon</span><span class=p>())</span><span class=w> </span><span class=k>noexcept</span>
<span class=p>{</span> <span class=p>{</span>
<span class=w> </span><span class=k>return</span><span class=w> </span><span class=n>std</span><span class=o>::</span><span class=n>abs</span><span class=p>(</span><span class=n>a</span><span class=w> </span><span class=o>-</span><span class=w> </span><span class=n>b</span><span class=p>)</span><span class=w> </span><span class=o>&lt;=</span><span class=w> </span><span class=n>epsilon</span><span class=p>;</span> <span class=w> </span><span class=k>return</span><span class=w> </span><span class=n>std</span><span class=o>::</span><span class=n>abs</span><span class=p>(</span><span class=n>a</span><span class=w> </span><span class=o>-</span><span class=w> </span><span class=n>b</span><span class=p>)</span><span class=w> </span><span class=o>&lt;=</span><span class=w> </span><span class=n>epsilon</span><span class=p>;</span>
@@ -115,4 +115,4 @@
<span class=mi>17</span><span class=w> </span><span class=err>==</span><span class=w> </span><span class=kc>null</span><span class=err>p</span><span class=kc>tr</span><span class=w> </span><span class=kc>false</span> <span class=mi>17</span><span class=w> </span><span class=err>==</span><span class=w> </span><span class=kc>null</span><span class=err>p</span><span class=kc>tr</span><span class=w> </span><span class=kc>false</span>
<span class=s2>"foo"</span><span class=w> </span><span class=err>==</span><span class=w> </span><span class=kc>null</span><span class=err>p</span><span class=kc>tr</span><span class=w> </span><span class=kc>false</span> <span class=s2>"foo"</span><span class=w> </span><span class=err>==</span><span class=w> </span><span class=kc>null</span><span class=err>p</span><span class=kc>tr</span><span class=w> </span><span class=kc>false</span>
<span class=kc>null</span><span class=w> </span><span class=err>==</span><span class=w> </span><span class=kc>null</span><span class=err>p</span><span class=kc>tr</span><span class=w> </span><span class=kc>true</span> <span class=kc>null</span><span class=w> </span><span class=err>==</span><span class=w> </span><span class=kc>null</span><span class=err>p</span><span class=kc>tr</span><span class=w> </span><span class=kc>true</span>
</code></pre></div> </details> <h2 id=see-also>See also<a class=headerlink href=#see-also title="Permanent link">&para;</a></h2> <ul> <li><a href=../operator_ne/ >operator!=</a> compare for inequality</li> <li><a href=../operator_spaceship/ >operator&lt;=&gt;</a> comparison: 3-way (C++20)</li> </ul> <h2 id=version-history>Version history<a class=headerlink href=#version-history title="Permanent link">&para;</a></h2> <ol> <li>Added in version 1.0.0. Added C++20 member functions in version 3.11.0.</li> <li>Added in version 1.0.0. Added C++20 member functions in version 3.11.0.</li> </ol> <!-- https://squidfunk.github.io/mkdocs-material/reference/tooltips/#adding-a-glossary --> <aside class=md-source-file> <span class=md-source-file__fact> <span class=md-icon title="Last update"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1zM12.5 7v5.2l4 2.4-1 1L11 13V7zM11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2z"/></svg> </span> <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date" title="October 2, 2026 09:32:15 UTC">October 2, 2026</span> </span> </aside> </article> </div> <script>var tabs=__md_get("__tabs");if(Array.isArray(tabs))e:for(var set of document.querySelectorAll(".tabbed-set")){var labels=set.querySelector(".tabbed-labels");for(var tab of tabs)for(var label of labels.getElementsByTagName("label"))if(label.innerText.trim()===tab){var input=document.getElementById(label.htmlFor);input.checked=!0;continue e}}</script> <script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script> </div> <button type=button class="md-top md-icon" data-md-component=top hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z"/></svg> Back to top </button> </main> <footer class=md-footer> <div class="md-footer-meta md-typeset"> <div class="md-footer-meta__inner md-grid"> <div class=md-copyright> <div class=md-copyright__highlight> Copyright &copy; 2013-2026 Niels Lohmann </div> </div> <div class=md-social> <a href="https://github.com/nlohmann" target="_blank" rel="noopener" title="github.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 512 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M173.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6m-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3m44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9M252.8 8C114.1 8 8 113.3 8 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C436.2 457.8 504 362.9 504 252 504 113.3 391.5 8 252.8 8M105.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1m-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7m32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1m-11.4-14.7c-1.6 1-1.6 3.6 0 5.9s4.3 3.3 5.6 2.3c1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2"/></svg> </a> <a href="https://www.linkedin.com/in/nielslohmann/" target="_blank" rel="noopener" title="www.linkedin.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 448 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M416 32H31.9C14.3 32 0 46.5 0 64.3v383.4C0 465.5 14.3 480 31.9 480H416c17.6 0 32-14.5 32-32.3V64.3c0-17.8-14.4-32.3-32-32.3M135.4 416H69V202.2h66.5V416zM102.2 96a38.5 38.5 0 1 1 0 77 38.5 38.5 0 1 1 0-77m282.1 320h-66.4V312c0-24.8-.5-56.7-34.5-56.7-34.6 0-39.9 27-39.9 54.9V416h-66.4V202.2h63.7v29.2h.9c8.9-16.8 30.6-34.5 62.9-34.5 67.2 0 79.7 44.3 79.7 101.9z"/></svg> </a> <a href="https://www.xing.com/profile/Niels_Lohmann" target="_blank" rel="noopener" title="www.xing.com" class="md-social__link"> <svg xmlns=http:Line truncated </code></pre></div> </details> <h2 id=see-also>See also<a class=headerlink href=#see-also title="Permanent link">&para;</a></h2> <ul> <li><a href=../operator_ne/ >operator!=</a> compare for inequality</li> <li><a href=../operator_spaceship/ >operator&lt;=&gt;</a> comparison: 3-way (C++20)</li> </ul> <h2 id=version-history>Version history<a class=headerlink href=#version-history title="Permanent link">&para;</a></h2> <ol> <li>Added in version 1.0.0. Added C++20 member functions in version 3.11.0.</li> <li>Added in version 1.0.0. Added C++20 member functions in version 3.11.0. Made conditionally <code class=highlight><span class=k>noexcept</span></code> in version 3.13.0 <span class=unreleased-version title="Not part of a release yet; the latest release is 3.12.0.">unreleased</span>; before, a throwing conversion called <code>std::terminate</code>.</li> </ol> <!-- https://squidfunk.github.io/mkdocs-material/reference/tooltips/#adding-a-glossary --> <aside class=md-source-file> <span class=md-source-file__fact> <span class=md-icon title="Last update"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1zM12.5 7v5.2l4 2.4-1 1L11 13V7zM11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2z"/></svg> </span> <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date" title="October 2, 2026 15:25:17 UTC">October 2, 2026</span> </span> </aside> </article> </div> <script>var tabs=__md_get("__tabs");if(Array.isArray(tabs))e:for(var set of document.querySelectorAll(".tabbed-set")){var labels=set.querySelector(".tabbed-labels");for(var tab of tabs)for(var label of labels.getElementsByTagName("label"))if(label.innerText.trim()===tab){var input=document.getElementById(label.htmlFor);input.checked=!0;continue e}}</script> <script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script> </div> <button type=button class="md-top md-icon" data-md-component=top hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z"/></svg> Back to top </button> </main> <footer class=md-footer> <div class="md-footer-meta md-typeset"> <div class="md-footer-meta__inner md-grid"> <div class=md-copyright> <div class=md-copyright__highlight> Copyright &copy; 2013-2026 Niels Lohmann </div> </div> <div class=md-social> <a href="https://github.com/nlohmann" target="_blank" rel="noopener" title="github.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 512 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M173.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6m-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3m44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9M252.8 8C114.1 8 8 113.3 8 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C436.2 457.8 504 362.9 504 252 504 113.3 391.5 8 252.8 8M105.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1m-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7m32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1m-11.4-14.7c-1.6 1-1.6 3.6 0 5.9s4.3 3.3 5.6 2.3c1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2"/></svg> </a> <a href="https://www.linkedin.com/in/nielslohmann/" target="_blank" rel="noopener" title="www.linkedin.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 448 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M416 32H31.9C14.3 32 0 46.5 0 64.3v383.4C0 465.5 14.3 480 31.9 480H416c17.6 0 32-14.5 32-32.3V64.3c0-17.8-14.4-32.3-32-32.3M135.4 416H69V202.2h66.5V416zM102.2 96a38.5 38.5 0 1 1 0 77 38.5 38.5 0 1 1 0-77m282.1 320h-66.4V312c0-24.8-.5-56.7-34.5-Line truncated
+6 -5
View File
@@ -5,17 +5,17 @@
bool operator==(const_reference lhs, const_reference rhs) noexcept; // (1) bool operator==(const_reference lhs, const_reference rhs) noexcept; // (1)
template<typename ScalarType> template<typename ScalarType>
bool operator==(const_reference lhs, const ScalarType rhs) noexcept; // (2) bool operator==(const_reference lhs, const ScalarType rhs) noexcept(/* see below */); // (2)
template<typename ScalarType> template<typename ScalarType>
bool operator==(ScalarType lhs, const const_reference rhs) noexcept; // (2) bool operator==(ScalarType lhs, const const_reference rhs) noexcept(/* see below */); // (2)
// since C++20 // since C++20
class basic_json { class basic_json {
bool operator==(const_reference rhs) const noexcept; // (1) bool operator==(const_reference rhs) const noexcept; // (1)
template<typename ScalarType> template<typename ScalarType>
bool operator==(ScalarType rhs) const noexcept; // (2) bool operator==(ScalarType rhs) const noexcept(/* see below */); // (2)
}; };
``` ```
@@ -42,7 +42,8 @@ whether the values `lhs`/`*this` and `rhs` are equal
## Exception safety ## Exception safety
No-throw guarantee: this function never throws exceptions. 1. No-throw guarantee: this function never throws exceptions.
1. No-throw guarantee if converting the scalar to a JSON value cannot throw, as for numbers, Booleans, and `nullptr`; the function is `noexcept` exactly in that case. Otherwise, it throws what the conversion throws, for example `std::bad_alloc` when converting a string, or [`out_of_range.410`](https://json.nlohmann.me/home/exceptions/#jsonexceptionout_of_range410) for an enum value not mapped by [`NLOHMANN_JSON_SERIALIZE_ENUM_STRICT`](https://json.nlohmann.me/api/macros/nlohmann_json_serialize_enum_strict/index.md).
## Complexity ## Complexity
@@ -228,4 +229,4 @@ null == nullptr true
## Version history ## Version history
1. Added in version 1.0.0. Added C++20 member functions in version 3.11.0. 1. Added in version 1.0.0. Added C++20 member functions in version 3.11.0.
1. Added in version 1.0.0. Added C++20 member functions in version 3.11.0. 1. Added in version 1.0.0. Added C++20 member functions in version 3.11.0. Made conditionally `noexcept` in version 3.13.0 unreleased; before, a throwing conversion called `std::terminate`.
+9 -3
View File
@@ -5,10 +5,10 @@
bool operator>=(const_reference lhs, const_reference rhs) noexcept; // (1) bool operator>=(const_reference lhs, const_reference rhs) noexcept; // (1)
template<typename ScalarType> template<typename ScalarType>
bool operator>=(const_reference lhs, const ScalarType rhs) noexcept; // (2) bool operator>=(const_reference lhs, const ScalarType rhs) noexcept(/* see below */); // (2)
template<typename ScalarType> template<typename ScalarType>
bool operator>=(ScalarType lhs, const const_reference rhs) noexcept; // (2) bool operator>=(ScalarType lhs, const const_reference rhs) noexcept(/* see below */); // (2)
``` ```
1. Compares whether one JSON value `lhs` is greater than or equal to another JSON value `rhs` according to the following 1. Compares whether one JSON value `lhs` is greater than or equal to another JSON value `rhs` according to the following
@@ -39,7 +39,12 @@ whether `lhs` is greater than or equal to `rhs`
## Exception safety ## Exception safety
No-throw guarantee: this function never throws exceptions. 1. No-throw guarantee: this function never throws exceptions.
2. No-throw guarantee if converting the scalar to a JSON value cannot throw, as for numbers, Booleans, and
`#!cpp nullptr`; the function is `#!cpp noexcept` exactly in that case. Otherwise, it throws what the conversion
throws, for example `std::bad_alloc` when converting a string, or
[`out_of_range.410`](../../home/exceptions.md#jsonexceptionout_of_range410) for an enum value not mapped by
[`NLOHMANN_JSON_SERIALIZE_ENUM_STRICT`](../macros/nlohmann_json_serialize_enum_strict.md).
## Complexity ## Complexity
@@ -94,3 +99,4 @@ Linear.
1. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0. 1. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0.
2. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0. 2. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0.
Made conditionally `#!cpp noexcept` in version 3.13.0; before, a throwing conversion called `std::terminate`.
+4 -4
View File
@@ -2,11 +2,11 @@
<span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&gt;=</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (1)</span> <span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&gt;=</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (1)</span>
<span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span> <span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span>
<span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&gt;=</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>ScalarType</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (2)</span> <span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&gt;=</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>ScalarType</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>(</span><span class=cm>/* see below */</span><span class=p>);</span><span class=w> </span><span class=c1>// (2)</span>
<span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span> <span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span>
<span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&gt;=</span><span class=p>(</span><span class=n>ScalarType</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (2)</span> <span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&gt;=</span><span class=p>(</span><span class=n>ScalarType</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>(</span><span class=cm>/* see below */</span><span class=p>);</span><span class=w> </span><span class=c1>// (2)</span>
</code></pre></div> <ol> <li> <p>Compares whether one <abbr title="JavaScript Object Notation">JSON</abbr> value <code>lhs</code> is greater than or equal to another <abbr title="JavaScript Object Notation">JSON</abbr> value <code>rhs</code> according to the following rules:</p> <ul> <li>The comparison always yields <code class=highlight><span class=nb>false</span></code> if (1) either operand is discarded, or (2) either operand is <code>NaN</code> and the other operand is either <code>NaN</code> or any other number.</li> <li>Otherwise, returns the result of <code class=highlight><span class=o>!</span><span class=p>(</span><span class=n>lhs</span><span class=w> </span><span class=o>&lt;</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span></code> (see <a href=../operator_lt/ ><strong>operator&lt;</strong></a>).</li> </ul> </li> <li> <p>Compares whether a <abbr title="JavaScript Object Notation">JSON</abbr> value is greater than or equal to a scalar or a scalar is greater than or equal to a <abbr title="JavaScript Object Notation">JSON</abbr> value by converting the scalar to a <abbr title="JavaScript Object Notation">JSON</abbr> value and comparing both <abbr title="JavaScript Object Notation">JSON</abbr> values according to 1.</p> </li> </ol> <h2 id=template-parameters>Template parameters<a class=headerlink href=#template-parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>ScalarType</code></dt> <dd>a scalar type according to <code>std::is_scalar&lt;ScalarType&gt;::value</code></dd> </dl> <h2 id=parameters>Parameters<a class=headerlink href=#parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>lhs</code> (in)</dt> <dd>first value to consider </dd> <dt><code>rhs</code> (in)</dt> <dd>second value to consider </dd> </dl> <h2 id=return-value>Return value<a class=headerlink href=#return-value title="Permanent link">&para;</a></h2> <p>whether <code>lhs</code> is greater than or equal to <code>rhs</code></p> <h2 id=exception-safety>Exception safety<a class=headerlink href=#exception-safety title="Permanent link">&para;</a></h2> <p>No-throw guarantee: this function never throws exceptions.</p> <h2 id=complexity>Complexity<a class=headerlink href=#complexity title="Permanent link">&para;</a></h2> <p>Linear.</p> <h2 id=notes>Notes<a class=headerlink href=#notes title="Permanent link">&para;</a></h2> <div class="admonition note"> <p class=admonition-title>Comparing <code>NaN</code></p> <p><code>NaN</code> values are unordered within the domain of numbers. The following comparisons all yield <code class=highlight><span class=nb>false</span></code>: 1. Comparing a <code>NaN</code> with itself. 2. Comparing a <code>NaN</code> with another <code>NaN</code>. 3. Comparing a <code>NaN</code> and any other number.</p> </div> <div class="admonition note"> <p class=admonition-title>Operator overload resolution</p> <p>Since C++20 overload resolution will consider the <em>rewritten candidate</em> generated from <a href=../operator_spaceship/ ><code>operator&lt;=&gt;</code></a>.</p> </div> <div class="admonition warning"> <p class=admonition-title>Deprecation</p> <p>If <a href=../../macros/json_use_legacy_discarded_value_comparison/ ><code>JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON</code></a> is defined to <code>1</code>, the library declares a member <code class=highlight><span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&gt;=</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=k>noexcept</span></code> in C++20 mode to emulate the legacy comparison of discarded values. This member is deprecated since version 3.11.0, together with the legacy comparison behavior.</p> <p>See the <a href=../../../integration/migration_guide/#miscellaneous-functions>migration guide</a> for how to update existing code.</p> </div> <h2 id=examples>Examples<a class=headerlink href=#examples title="Permanent link">&para;</a></h2> <details class=example> <summary>Example</summary> <p>The example demonstrates comparing several <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class=highlight><pre><span></span><code><span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;iostream&gt;</span> </code></pre></div> <ol> <li> <p>Compares whether one <abbr title="JavaScript Object Notation">JSON</abbr> value <code>lhs</code> is greater than or equal to another <abbr title="JavaScript Object Notation">JSON</abbr> value <code>rhs</code> according to the following rules:</p> <ul> <li>The comparison always yields <code class=highlight><span class=nb>false</span></code> if (1) either operand is discarded, or (2) either operand is <code>NaN</code> and the other operand is either <code>NaN</code> or any other number.</li> <li>Otherwise, returns the result of <code class=highlight><span class=o>!</span><span class=p>(</span><span class=n>lhs</span><span class=w> </span><span class=o>&lt;</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span></code> (see <a href=../operator_lt/ ><strong>operator&lt;</strong></a>).</li> </ul> </li> <li> <p>Compares whether a <abbr title="JavaScript Object Notation">JSON</abbr> value is greater than or equal to a scalar or a scalar is greater than or equal to a <abbr title="JavaScript Object Notation">JSON</abbr> value by converting the scalar to a <abbr title="JavaScript Object Notation">JSON</abbr> value and comparing both <abbr title="JavaScript Object Notation">JSON</abbr> values according to 1.</p> </li> </ol> <h2 id=template-parameters>Template parameters<a class=headerlink href=#template-parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>ScalarType</code></dt> <dd>a scalar type according to <code>std::is_scalar&lt;ScalarType&gt;::value</code></dd> </dl> <h2 id=parameters>Parameters<a class=headerlink href=#parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>lhs</code> (in)</dt> <dd>first value to consider </dd> <dt><code>rhs</code> (in)</dt> <dd>second value to consider </dd> </dl> <h2 id=return-value>Return value<a class=headerlink href=#return-value title="Permanent link">&para;</a></h2> <p>whether <code>lhs</code> is greater than or equal to <code>rhs</code></p> <h2 id=exception-safety>Exception safety<a class=headerlink href=#exception-safety title="Permanent link">&para;</a></h2> <ol> <li>No-throw guarantee: this function never throws exceptions.</li> <li>No-throw guarantee if converting the scalar to a <abbr title="JavaScript Object Notation">JSON</abbr> value cannot throw, as for numbers, Booleans, and <code class=highlight><span class=nb>nullptr</span></code>; the function is <code class=highlight><span class=k>noexcept</span></code> exactly in that case. Otherwise, it throws what the conversion throws, for example <code>std::bad_alloc</code> when converting a string, or <a href=../../../home/exceptions/#jsonexceptionout_of_range410><code>out_of_range.410</code></a> for an enum value not mapped by <a href=../../macros/nlohmann_json_serialize_enum_strict/ ><code>NLOHMANN_JSON_SERIALIZE_ENUM_STRICT</code></a>.</li> </ol> <h2 id=complexity>Complexity<a class=headerlink href=#complexity title="Permanent link">&para;</a></h2> <p>Linear.</p> <h2 id=notes>Notes<a class=headerlink href=#notes title="Permanent link">&para;</a></h2> <div class="admonition note"> <p class=admonition-title>Comparing <code>NaN</code></p> <p><code>NaN</code> values are unordered within the domain of numbers. The following comparisons all yield <code class=highlight><span class=nb>false</span></code>: 1. Comparing a <code>NaN</code> with itself. 2. Comparing a <code>NaN</code> with another <code>NaN</code>. 3. Comparing a <code>NaN</code> and any other number.</p> </div> <div class="admonition note"> <p class=admonition-title>Operator overload resolution</p> <p>Since C++20 overload resolution will consider the <em>rewritten candidate</em> generated from <a href=../operator_spaceship/ ><code>operator&lt;=&gt;</code></a>.</p> </div> <div class="admonition warning"> <p class=admonition-title>Deprecation</p> <p>If <a href=../../macros/json_use_legacy_discarded_value_comparison/ ><code>JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON</code></a> is defined to <code>1</code>, the library declares a member <code class=highlight><span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&gt;=</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=k>noexcept</span></code> in C++20 mode to emulate the legacy comparison of discarded values. This member is deprecated since version 3.11.0, together with the legacy comparison behavior.</p> <p>See the <a href=../../../integration/migration_guide/#miscellaneous-functions>migration guide</a> for how to update existing code.</p> </div> <h2 id=examples>Examples<a class=headerlink href=#examples title="Permanent link">&para;</a></h2> <details class=example> <summary>Example</summary> <p>The example demonstrates comparing several <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class=highlight><pre><span></span><code>Line truncated
<span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;nlohmann/json.hpp&gt;</span> <span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;nlohmann/json.hpp&gt;</span>
<span class=k>using</span><span class=w> </span><span class=n>json</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=n>nlohmann</span><span class=o>::</span><span class=n>json</span><span class=p>;</span> <span class=k>using</span><span class=w> </span><span class=n>json</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=n>nlohmann</span><span class=o>::</span><span class=n>json</span><span class=p>;</span>
@@ -34,4 +34,4 @@
<span class=p>{</span><span class=nt>"A"</span><span class=p>:</span><span class=s2>"a"</span><span class=p>,</span><span class=nt>"B"</span><span class=p>:</span><span class=s2>"b"</span><span class=p>}</span><span class=w> </span><span class=err>&gt;=</span><span class=w> </span><span class=p>{</span><span class=nt>"A"</span><span class=p>:</span><span class=s2>"a"</span><span class=p>,</span><span class=nt>"B"</span><span class=p>:</span><span class=s2>"b"</span><span class=p>}</span><span class=w> </span><span class=kc>true</span> <span class=p>{</span><span class=nt>"A"</span><span class=p>:</span><span class=s2>"a"</span><span class=p>,</span><span class=nt>"B"</span><span class=p>:</span><span class=s2>"b"</span><span class=p>}</span><span class=w> </span><span class=err>&gt;=</span><span class=w> </span><span class=p>{</span><span class=nt>"A"</span><span class=p>:</span><span class=s2>"a"</span><span class=p>,</span><span class=nt>"B"</span><span class=p>:</span><span class=s2>"b"</span><span class=p>}</span><span class=w> </span><span class=kc>true</span>
<span class=mi>17</span><span class=w> </span><span class=err>&gt;=</span><span class=w> </span><span class=mf>17.0000000000001</span><span class=w> </span><span class=kc>false</span> <span class=mi>17</span><span class=w> </span><span class=err>&gt;=</span><span class=w> </span><span class=mf>17.0000000000001</span><span class=w> </span><span class=kc>false</span>
<span class=s2>"foo"</span><span class=w> </span><span class=err>&gt;=</span><span class=w> </span><span class=s2>"bar"</span><span class=w> </span><span class=kc>true</span> <span class=s2>"foo"</span><span class=w> </span><span class=err>&gt;=</span><span class=w> </span><span class=s2>"bar"</span><span class=w> </span><span class=kc>true</span>
</code></pre></div> </details> <h2 id=see-also>See also<a class=headerlink href=#see-also title="Permanent link">&para;</a></h2> <ul> <li><a href=../operator_spaceship/ ><strong>operator&lt;=&gt;</strong></a> comparison: 3-way</li> </ul> <h2 id=version-history>Version history<a class=headerlink href=#version-history title="Permanent link">&para;</a></h2> <ol> <li>Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0.</li> <li>Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0.</li> </ol> <!-- https://squidfunk.github.io/mkdocs-material/reference/tooltips/#adding-a-glossary --> <aside class=md-source-file> <span class=md-source-file__fact> <span class=md-icon title="Last update"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1zM12.5 7v5.2l4 2.4-1 1L11 13V7zM11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2z"/></svg> </span> <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date" title="October 2, 2026 09:32:15 UTC">October 2, 2026</span> </span> </aside> </article> </div> <script>var tabs=__md_get("__tabs");if(Array.isArray(tabs))e:for(var set of document.querySelectorAll(".tabbed-set")){var labels=set.querySelector(".tabbed-labels");for(var tab of tabs)for(var label of labels.getElementsByTagName("label"))if(label.innerText.trim()===tab){var input=document.getElementById(label.htmlFor);input.checked=!0;continue e}}</script> <script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script> </div> <button type=button class="md-top md-icon" data-md-component=top hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z"/></svg> Back to top </button> </main> <footer class=md-footer> <div class="md-footer-meta md-typeset"> <div class="md-footer-meta__inner md-grid"> <div class=md-copyright> <div class=md-copyright__highlight> Copyright &copy; 2013-2026 Niels Lohmann </div> </div> <div class=md-social> <a href="https://github.com/nlohmann" target="_blank" rel="noopener" title="github.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 512 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M173.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6m-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3m44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9M252.8 8C114.1 8 8 113.3 8 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C436.2 457.8 504 362.9 504 252 504 113.3 391.5 8 252.8 8M105.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1m-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7m32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1m-11.4-14.7c-1.6 1-1.6 3.6 0 5.9s4.3 3.3 5.6 2.3c1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2"/></svg> </a> <a href="https://www.linkedin.com/in/nielslohmann/" target="_blank" rel="noopener" title="www.linkedin.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 448 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M416 32H31.9C14.3 32 0 46.5 0 64.3v383.4C0 465.5 14.3 480 31.9 480H416c17.6 0 32-14.5 32-32.3V64.3c0-17.8-14.4-32.3-32-32.3M135.4 416H69V202.2h66.5V416zM102.2 96a38.5 38.5 0 1 1 0 77 38.5 38.5 0 1 1 0-77m282.1 320h-66.4V312c0-24.8-.5-56.7-34.5-56.7-34.6 0-39.9 27-39.9 54.9V416h-66.4V202.2h63.7v29.2h.9c8.9-16.8 30.6-34.5 62.9-34.5 67.2 0 79.7 44.3 79.7 101.9z"/></svg> </a> <a href="https://www.xing.com/profile/Niels_Lohmann" target="_blank" rel="noopener" title="www.xing.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 384 512"><!-- FontLine truncated </code></pre></div> </details> <h2 id=see-also>See also<a class=headerlink href=#see-also title="Permanent link">&para;</a></h2> <ul> <li><a href=../operator_spaceship/ ><strong>operator&lt;=&gt;</strong></a> comparison: 3-way</li> </ul> <h2 id=version-history>Version history<a class=headerlink href=#version-history title="Permanent link">&para;</a></h2> <ol> <li>Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0.</li> <li>Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0. Made conditionally <code class=highlight><span class=k>noexcept</span></code> in version 3.13.0 <span class=unreleased-version title="Not part of a release yet; the latest release is 3.12.0.">unreleased</span>; before, a throwing conversion called <code>std::terminate</code>.</li> </ol> <!-- https://squidfunk.github.io/mkdocs-material/reference/tooltips/#adding-a-glossary --> <aside class=md-source-file> <span class=md-source-file__fact> <span class=md-icon title="Last update"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1zM12.5 7v5.2l4 2.4-1 1L11 13V7zM11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2z"/></svg> </span> <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date" title="October 2, 2026 15:25:17 UTC">October 2, 2026</span> </span> </aside> </article> </div> <script>var tabs=__md_get("__tabs");if(Array.isArray(tabs))e:for(var set of document.querySelectorAll(".tabbed-set")){var labels=set.querySelector(".tabbed-labels");for(var tab of tabs)for(var label of labels.getElementsByTagName("label"))if(label.innerText.trim()===tab){var input=document.getElementById(label.htmlFor);input.checked=!0;continue e}}</script> <script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script> </div> <button type=button class="md-top md-icon" data-md-component=top hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z"/></svg> Back to top </button> </main> <footer class=md-footer> <div class="md-footer-meta md-typeset"> <div class="md-footer-meta__inner md-grid"> <div class=md-copyright> <div class=md-copyright__highlight> Copyright &copy; 2013-2026 Niels Lohmann </div> </div> <div class=md-social> <a href="https://github.com/nlohmann" target="_blank" rel="noopener" title="github.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 512 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M173.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6m-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3m44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9M252.8 8C114.1 8 8 113.3 8 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C436.2 457.8 504 362.9 504 252 504 113.3 391.5 8 252.8 8M105.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1m-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7m32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1m-11.4-14.7c-1.6 1-1.6 3.6 0 5.9s4.3 3.3 5.6 2.3c1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2"/></svg> </a> <a href="https://www.linkedin.com/in/nielslohmann/" target="_blank" rel="noopener" title="www.linkedin.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 448 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M416 32H31.9C14.3 32 0 46.5 0 64.3v383.4C0 465.5 14.3 480 31.9 480H416c17.6 0 32-14.5 32-32.3V64.3c0-17.8-14.4-32.3-32-32.3M135.4 416H69V202.2h66.5V416zM102.2 96a38.5 38.5 0 1 1 0 77 38.5 38.5 0 1 1 0-77m282.1 320h-66.4V312c0-24.8-.5-56.7-34.5-56.7-34.6 0-39.9 27-39.9 54.9V416h-66.4V202.2h63.7v29Line truncated
+5 -4
View File
@@ -5,10 +5,10 @@
bool operator>=(const_reference lhs, const_reference rhs) noexcept; // (1) bool operator>=(const_reference lhs, const_reference rhs) noexcept; // (1)
template<typename ScalarType> template<typename ScalarType>
bool operator>=(const_reference lhs, const ScalarType rhs) noexcept; // (2) bool operator>=(const_reference lhs, const ScalarType rhs) noexcept(/* see below */); // (2)
template<typename ScalarType> template<typename ScalarType>
bool operator>=(ScalarType lhs, const const_reference rhs) noexcept; // (2) bool operator>=(ScalarType lhs, const const_reference rhs) noexcept(/* see below */); // (2)
``` ```
1. Compares whether one JSON value `lhs` is greater than or equal to another JSON value `rhs` according to the following rules: 1. Compares whether one JSON value `lhs` is greater than or equal to another JSON value `rhs` according to the following rules:
@@ -34,7 +34,8 @@ whether `lhs` is greater than or equal to `rhs`
## Exception safety ## Exception safety
No-throw guarantee: this function never throws exceptions. 1. No-throw guarantee: this function never throws exceptions.
1. No-throw guarantee if converting the scalar to a JSON value cannot throw, as for numbers, Booleans, and `nullptr`; the function is `noexcept` exactly in that case. Otherwise, it throws what the conversion throws, for example `std::bad_alloc` when converting a string, or [`out_of_range.410`](https://json.nlohmann.me/home/exceptions/#jsonexceptionout_of_range410) for an enum value not mapped by [`NLOHMANN_JSON_SERIALIZE_ENUM_STRICT`](https://json.nlohmann.me/api/macros/nlohmann_json_serialize_enum_strict/index.md).
## Complexity ## Complexity
@@ -109,4 +110,4 @@ Output:
## Version history ## Version history
1. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0. 1. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0.
1. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0. 1. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0. Made conditionally `noexcept` in version 3.13.0 unreleased; before, a throwing conversion called `std::terminate`.
+9 -3
View File
@@ -5,10 +5,10 @@
bool operator>(const_reference lhs, const_reference rhs) noexcept; // (1) bool operator>(const_reference lhs, const_reference rhs) noexcept; // (1)
template<typename ScalarType> template<typename ScalarType>
bool operator>(const_reference lhs, const ScalarType rhs) noexcept; // (2) bool operator>(const_reference lhs, const ScalarType rhs) noexcept(/* see below */); // (2)
template<typename ScalarType> template<typename ScalarType>
bool operator>(ScalarType lhs, const const_reference rhs) noexcept; // (2) bool operator>(ScalarType lhs, const const_reference rhs) noexcept(/* see below */); // (2)
``` ```
1. Compares whether one JSON value `lhs` is greater than another JSON value `rhs` according to the 1. Compares whether one JSON value `lhs` is greater than another JSON value `rhs` according to the
@@ -39,7 +39,12 @@ whether `lhs` is greater than `rhs`
## Exception safety ## Exception safety
No-throw guarantee: this function never throws exceptions. 1. No-throw guarantee: this function never throws exceptions.
2. No-throw guarantee if converting the scalar to a JSON value cannot throw, as for numbers, Booleans, and
`#!cpp nullptr`; the function is `#!cpp noexcept` exactly in that case. Otherwise, it throws what the conversion
throws, for example `std::bad_alloc` when converting a string, or
[`out_of_range.410`](../../home/exceptions.md#jsonexceptionout_of_range410) for an enum value not mapped by
[`NLOHMANN_JSON_SERIALIZE_ENUM_STRICT`](../macros/nlohmann_json_serialize_enum_strict.md).
## Complexity ## Complexity
@@ -84,3 +89,4 @@ Linear.
1. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0. 1. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0.
2. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0. 2. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0.
Made conditionally `#!cpp noexcept` in version 3.13.0; before, a throwing conversion called `std::terminate`.
+4 -4
View File
@@ -2,11 +2,11 @@
<span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&gt;</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (1)</span> <span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&gt;</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (1)</span>
<span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span> <span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span>
<span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&gt;</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>ScalarType</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (2)</span> <span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&gt;</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>ScalarType</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>(</span><span class=cm>/* see below */</span><span class=p>);</span><span class=w> </span><span class=c1>// (2)</span>
<span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span> <span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span>
<span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&gt;</span><span class=p>(</span><span class=n>ScalarType</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (2)</span> <span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&gt;</span><span class=p>(</span><span class=n>ScalarType</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>(</span><span class=cm>/* see below */</span><span class=p>);</span><span class=w> </span><span class=c1>// (2)</span>
</code></pre></div> <ol> <li> <p>Compares whether one <abbr title="JavaScript Object Notation">JSON</abbr> value <code>lhs</code> is greater than another <abbr title="JavaScript Object Notation">JSON</abbr> value <code>rhs</code> according to the following rules:</p> <ul> <li>The comparison always yields <code class=highlight><span class=nb>false</span></code> if (1) either operand is discarded, or (2) either operand is <code>NaN</code> and the other operand is either <code>NaN</code> or any other number.</li> <li>Otherwise, returns the result of <code class=highlight><span class=o>!</span><span class=p>(</span><span class=n>lhs</span><span class=w> </span><span class=o>&lt;=</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span></code> (see <a href=../operator_le/ ><strong>operator&lt;=</strong></a>).</li> </ul> </li> <li> <p>Compares whether a <abbr title="JavaScript Object Notation">JSON</abbr> value is greater than a scalar or a scalar is greater than a <abbr title="JavaScript Object Notation">JSON</abbr> value by converting the scalar to a <abbr title="JavaScript Object Notation">JSON</abbr> value and comparing both <abbr title="JavaScript Object Notation">JSON</abbr> values according to 1.</p> </li> </ol> <h2 id=template-parameters>Template parameters<a class=headerlink href=#template-parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>ScalarType</code></dt> <dd>a scalar type according to <code>std::is_scalar&lt;ScalarType&gt;::value</code></dd> </dl> <h2 id=parameters>Parameters<a class=headerlink href=#parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>lhs</code> (in)</dt> <dd>first value to consider </dd> <dt><code>rhs</code> (in)</dt> <dd>second value to consider </dd> </dl> <h2 id=return-value>Return value<a class=headerlink href=#return-value title="Permanent link">&para;</a></h2> <p>whether <code>lhs</code> is greater than <code>rhs</code></p> <h2 id=exception-safety>Exception safety<a class=headerlink href=#exception-safety title="Permanent link">&para;</a></h2> <p>No-throw guarantee: this function never throws exceptions.</p> <h2 id=complexity>Complexity<a class=headerlink href=#complexity title="Permanent link">&para;</a></h2> <p>Linear.</p> <h2 id=notes>Notes<a class=headerlink href=#notes title="Permanent link">&para;</a></h2> <div class="admonition note"> <p class=admonition-title>Comparing <code>NaN</code></p> <p><code>NaN</code> values are unordered within the domain of numbers. The following comparisons all yield <code class=highlight><span class=nb>false</span></code>: 1. Comparing a <code>NaN</code> with itself. 2. Comparing a <code>NaN</code> with another <code>NaN</code>. 3. Comparing a <code>NaN</code> and any other number.</p> </div> <div class="admonition note"> <p class=admonition-title>Operator overload resolution</p> <p>Since C++20 overload resolution will consider the <em>rewritten candidate</em> generated from <a href=../operator_spaceship/ ><code>operator&lt;=&gt;</code></a>.</p> </div> <h2 id=examples>Examples<a class=headerlink href=#examples title="Permanent link">&para;</a></h2> <details class=example> <summary>Example</summary> <p>The example demonstrates comparing several <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class=highlight><pre><span></span><code><span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;iostream&gt;</span> </code></pre></div> <ol> <li> <p>Compares whether one <abbr title="JavaScript Object Notation">JSON</abbr> value <code>lhs</code> is greater than another <abbr title="JavaScript Object Notation">JSON</abbr> value <code>rhs</code> according to the following rules:</p> <ul> <li>The comparison always yields <code class=highlight><span class=nb>false</span></code> if (1) either operand is discarded, or (2) either operand is <code>NaN</code> and the other operand is either <code>NaN</code> or any other number.</li> <li>Otherwise, returns the result of <code class=highlight><span class=o>!</span><span class=p>(</span><span class=n>lhs</span><span class=w> </span><span class=o>&lt;=</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span></code> (see <a href=../operator_le/ ><strong>operator&lt;=</strong></a>).</li> </ul> </li> <li> <p>Compares whether a <abbr title="JavaScript Object Notation">JSON</abbr> value is greater than a scalar or a scalar is greater than a <abbr title="JavaScript Object Notation">JSON</abbr> value by converting the scalar to a <abbr title="JavaScript Object Notation">JSON</abbr> value and comparing both <abbr title="JavaScript Object Notation">JSON</abbr> values according to 1.</p> </li> </ol> <h2 id=template-parameters>Template parameters<a class=headerlink href=#template-parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>ScalarType</code></dt> <dd>a scalar type according to <code>std::is_scalar&lt;ScalarType&gt;::value</code></dd> </dl> <h2 id=parameters>Parameters<a class=headerlink href=#parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>lhs</code> (in)</dt> <dd>first value to consider </dd> <dt><code>rhs</code> (in)</dt> <dd>second value to consider </dd> </dl> <h2 id=return-value>Return value<a class=headerlink href=#return-value title="Permanent link">&para;</a></h2> <p>whether <code>lhs</code> is greater than <code>rhs</code></p> <h2 id=exception-safety>Exception safety<a class=headerlink href=#exception-safety title="Permanent link">&para;</a></h2> <ol> <li>No-throw guarantee: this function never throws exceptions.</li> <li>No-throw guarantee if converting the scalar to a <abbr title="JavaScript Object Notation">JSON</abbr> value cannot throw, as for numbers, Booleans, and <code class=highlight><span class=nb>nullptr</span></code>; the function is <code class=highlight><span class=k>noexcept</span></code> exactly in that case. Otherwise, it throws what the conversion throws, for example <code>std::bad_alloc</code> when converting a string, or <a href=../../../home/exceptions/#jsonexceptionout_of_range410><code>out_of_range.410</code></a> for an enum value not mapped by <a href=../../macros/nlohmann_json_serialize_enum_strict/ ><code>NLOHMANN_JSON_SERIALIZE_ENUM_STRICT</code></a>.</li> </ol> <h2 id=complexity>Complexity<a class=headerlink href=#complexity title="Permanent link">&para;</a></h2> <p>Linear.</p> <h2 id=notes>Notes<a class=headerlink href=#notes title="Permanent link">&para;</a></h2> <div class="admonition note"> <p class=admonition-title>Comparing <code>NaN</code></p> <p><code>NaN</code> values are unordered within the domain of numbers. The following comparisons all yield <code class=highlight><span class=nb>false</span></code>: 1. Comparing a <code>NaN</code> with itself. 2. Comparing a <code>NaN</code> with another <code>NaN</code>. 3. Comparing a <code>NaN</code> and any other number.</p> </div> <div class="admonition note"> <p class=admonition-title>Operator overload resolution</p> <p>Since C++20 overload resolution will consider the <em>rewritten candidate</em> generated from <a href=../operator_spaceship/ ><code>operator&lt;=&gt;</code></a>.</p> </div> <h2 id=examples>Examples<a class=headerlink href=#examples title="Permanent link">&para;</a></h2> <details class=example> <summary>Example</summary> <p>The example demonstrates comparing several <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class=highlight><pre><span></span><code><span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;iostream&gt;</span>
<span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;nlohmann/json.hpp&gt;</span> <span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;nlohmann/json.hpp&gt;</span>
<span class=k>using</span><span class=w> </span><span class=n>json</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=n>nlohmann</span><span class=o>::</span><span class=n>json</span><span class=p>;</span> <span class=k>using</span><span class=w> </span><span class=n>json</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=n>nlohmann</span><span class=o>::</span><span class=n>json</span><span class=p>;</span>
@@ -34,4 +34,4 @@
<span class=p>{</span><span class=nt>"A"</span><span class=p>:</span><span class=s2>"a"</span><span class=p>,</span><span class=nt>"B"</span><span class=p>:</span><span class=s2>"b"</span><span class=p>}</span><span class=w> </span><span class=err>&gt;</span><span class=w> </span><span class=p>{</span><span class=nt>"A"</span><span class=p>:</span><span class=s2>"a"</span><span class=p>,</span><span class=nt>"B"</span><span class=p>:</span><span class=s2>"b"</span><span class=p>}</span><span class=w> </span><span class=kc>false</span> <span class=p>{</span><span class=nt>"A"</span><span class=p>:</span><span class=s2>"a"</span><span class=p>,</span><span class=nt>"B"</span><span class=p>:</span><span class=s2>"b"</span><span class=p>}</span><span class=w> </span><span class=err>&gt;</span><span class=w> </span><span class=p>{</span><span class=nt>"A"</span><span class=p>:</span><span class=s2>"a"</span><span class=p>,</span><span class=nt>"B"</span><span class=p>:</span><span class=s2>"b"</span><span class=p>}</span><span class=w> </span><span class=kc>false</span>
<span class=mi>17</span><span class=w> </span><span class=err>&gt;</span><span class=w> </span><span class=mf>17.0000000000001</span><span class=w> </span><span class=kc>false</span> <span class=mi>17</span><span class=w> </span><span class=err>&gt;</span><span class=w> </span><span class=mf>17.0000000000001</span><span class=w> </span><span class=kc>false</span>
<span class=s2>"foo"</span><span class=w> </span><span class=err>&gt;</span><span class=w> </span><span class=s2>"bar"</span><span class=w> </span><span class=kc>true</span> <span class=s2>"foo"</span><span class=w> </span><span class=err>&gt;</span><span class=w> </span><span class=s2>"bar"</span><span class=w> </span><span class=kc>true</span>
</code></pre></div> </details> <h2 id=see-also>See also<a class=headerlink href=#see-also title="Permanent link">&para;</a></h2> <ul> <li><a href=../operator_spaceship/ ><strong>operator&lt;=&gt;</strong></a> comparison: 3-way</li> </ul> <h2 id=version-history>Version history<a class=headerlink href=#version-history title="Permanent link">&para;</a></h2> <ol> <li>Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0.</li> <li>Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0.</li> </ol> <!-- https://squidfunk.github.io/mkdocs-material/reference/tooltips/#adding-a-glossary --> <aside class=md-source-file> <span class=md-source-file__fact> <span class=md-icon title="Last update"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1zM12.5 7v5.2l4 2.4-1 1L11 13V7zM11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2z"/></svg> </span> <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date" title="July 7, 2024 08:22:17 UTC">July 7, 2024</span> </span> </aside> </article> </div> <script>var tabs=__md_get("__tabs");if(Array.isArray(tabs))e:for(var set of document.querySelectorAll(".tabbed-set")){var labels=set.querySelector(".tabbed-labels");for(var tab of tabs)for(var label of labels.getElementsByTagName("label"))if(label.innerText.trim()===tab){var input=document.getElementById(label.htmlFor);input.checked=!0;continue e}}</script> <script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script> </div> <button type=button class="md-top md-icon" data-md-component=top hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z"/></svg> Back to top </button> </main> <footer class=md-footer> <div class="md-footer-meta md-typeset"> <div class="md-footer-meta__inner md-grid"> <div class=md-copyright> <div class=md-copyright__highlight> Copyright &copy; 2013-2026 Niels Lohmann </div> </div> <div class=md-social> <a href="https://github.com/nlohmann" target="_blank" rel="noopener" title="github.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 512 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M173.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6m-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3m44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9M252.8 8C114.1 8 8 113.3 8 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C436.2 457.8 504 362.9 504 252 504 113.3 391.5 8 252.8 8M105.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1m-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7m32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1m-11.4-14.7c-1.6 1-1.6 3.6 0 5.9s4.3 3.3 5.6 2.3c1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2"/></svg> </a> <a href="https://www.linkedin.com/in/nielslohmann/" target="_blank" rel="noopener" title="www.linkedin.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 448 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M416 32H31.9C14.3 32 0 46.5 0 64.3v383.4C0 465.5 14.3 480 31.9 480H416c17.6 0 32-14.5 32-32.3V64.3c0-17.8-14.4-32.3-32-32.3M135.4 416H69V202.2h66.5V416zM102.2 96a38.5 38.5 0 1 1 0 77 38.5 38.5 0 1 1 0-77m282.1 320h-66.4V312c0-24.8-.5-56.7-34.5-56.7-34.6 0-39.9 27-39.9 54.9V416h-66.4V202.2h63.7v29.2h.9c8.9-16.8 30.6-34.5 62.9-34.5 67.2 0 79.7 44.3 79.7 101.9z"/></svg> </a> <a href="https://www.xing.com/profile/Niels_Lohmann" target="_blank" rel="noopener" title="www.xing.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 384 512"><!-- Font AwesoLine truncated </code></pre></div> </details> <h2 id=see-also>See also<a class=headerlink href=#see-also title="Permanent link">&para;</a></h2> <ul> <li><a href=../operator_spaceship/ ><strong>operator&lt;=&gt;</strong></a> comparison: 3-way</li> </ul> <h2 id=version-history>Version history<a class=headerlink href=#version-history title="Permanent link">&para;</a></h2> <ol> <li>Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0.</li> <li>Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0. Made conditionally <code class=highlight><span class=k>noexcept</span></code> in version 3.13.0 <span class=unreleased-version title="Not part of a release yet; the latest release is 3.12.0.">unreleased</span>; before, a throwing conversion called <code>std::terminate</code>.</li> </ol> <!-- https://squidfunk.github.io/mkdocs-material/reference/tooltips/#adding-a-glossary --> <aside class=md-source-file> <span class=md-source-file__fact> <span class=md-icon title="Last update"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1zM12.5 7v5.2l4 2.4-1 1L11 13V7zM11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2z"/></svg> </span> <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date" title="October 2, 2026 15:25:17 UTC">October 2, 2026</span> </span> </aside> </article> </div> <script>var tabs=__md_get("__tabs");if(Array.isArray(tabs))e:for(var set of document.querySelectorAll(".tabbed-set")){var labels=set.querySelector(".tabbed-labels");for(var tab of tabs)for(var label of labels.getElementsByTagName("label"))if(label.innerText.trim()===tab){var input=document.getElementById(label.htmlFor);input.checked=!0;continue e}}</script> <script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script> </div> <button type=button class="md-top md-icon" data-md-component=top hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z"/></svg> Back to top </button> </main> <footer class=md-footer> <div class="md-footer-meta md-typeset"> <div class="md-footer-meta__inner md-grid"> <div class=md-copyright> <div class=md-copyright__highlight> Copyright &copy; 2013-2026 Niels Lohmann </div> </div> <div class=md-social> <a href="https://github.com/nlohmann" target="_blank" rel="noopener" title="github.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 512 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M173.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6m-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3m44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9M252.8 8C114.1 8 8 113.3 8 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C436.2 457.8 504 362.9 504 252 504 113.3 391.5 8 252.8 8M105.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1m-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7m32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1m-11.4-14.7c-1.6 1-1.6 3.6 0 5.9s4.3 3.3 5.6 2.3c1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2"/></svg> </a> <a href="https://www.linkedin.com/in/nielslohmann/" target="_blank" rel="noopener" title="www.linkedin.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 448 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M416 32H31.9C14.3 32 0 46.5 0 64.3v383.4C0 465.5 14.3 480 31.9 480H416c17.6 0 32-14.5 32-32.3V64.3c0-17.8-14.4-32.3-32-32.3M135.4 416H69V202.2h66.5V416zM102.2 96a38.5 38.5 0 1 1 0 77 38.5 38.5 0 1 1 0-77m282.1 320h-66.4V312c0-24.8-.5-56.7-34.5-56.7-34.6 0-39.9 27-39.9 54.9V416h-66.4V202.2h63.7v29Line truncated
+5 -4
View File
@@ -5,10 +5,10 @@
bool operator>(const_reference lhs, const_reference rhs) noexcept; // (1) bool operator>(const_reference lhs, const_reference rhs) noexcept; // (1)
template<typename ScalarType> template<typename ScalarType>
bool operator>(const_reference lhs, const ScalarType rhs) noexcept; // (2) bool operator>(const_reference lhs, const ScalarType rhs) noexcept(/* see below */); // (2)
template<typename ScalarType> template<typename ScalarType>
bool operator>(ScalarType lhs, const const_reference rhs) noexcept; // (2) bool operator>(ScalarType lhs, const const_reference rhs) noexcept(/* see below */); // (2)
``` ```
1. Compares whether one JSON value `lhs` is greater than another JSON value `rhs` according to the following rules: 1. Compares whether one JSON value `lhs` is greater than another JSON value `rhs` according to the following rules:
@@ -34,7 +34,8 @@ whether `lhs` is greater than `rhs`
## Exception safety ## Exception safety
No-throw guarantee: this function never throws exceptions. 1. No-throw guarantee: this function never throws exceptions.
1. No-throw guarantee if converting the scalar to a JSON value cannot throw, as for numbers, Booleans, and `nullptr`; the function is `noexcept` exactly in that case. Otherwise, it throws what the conversion throws, for example `std::bad_alloc` when converting a string, or [`out_of_range.410`](https://json.nlohmann.me/home/exceptions/#jsonexceptionout_of_range410) for an enum value not mapped by [`NLOHMANN_JSON_SERIALIZE_ENUM_STRICT`](https://json.nlohmann.me/api/macros/nlohmann_json_serialize_enum_strict/index.md).
## Complexity ## Complexity
@@ -103,4 +104,4 @@ Output:
## Version history ## Version history
1. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0. 1. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0.
1. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0. 1. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0. Made conditionally `noexcept` in version 3.13.0 unreleased; before, a throwing conversion called `std::terminate`.
+9 -3
View File
@@ -5,10 +5,10 @@
bool operator<=(const_reference lhs, const_reference rhs) noexcept; // (1) bool operator<=(const_reference lhs, const_reference rhs) noexcept; // (1)
template<typename ScalarType> template<typename ScalarType>
bool operator<=(const_reference lhs, const ScalarType rhs) noexcept; // (2) bool operator<=(const_reference lhs, const ScalarType rhs) noexcept(/* see below */); // (2)
template<typename ScalarType> template<typename ScalarType>
bool operator<=(ScalarType lhs, const const_reference rhs) noexcept; // (2) bool operator<=(ScalarType lhs, const const_reference rhs) noexcept(/* see below */); // (2)
``` ```
1. Compares whether one JSON value `lhs` is less than or equal to another JSON value `rhs` 1. Compares whether one JSON value `lhs` is less than or equal to another JSON value `rhs`
@@ -40,7 +40,12 @@ whether `lhs` is less than or equal to `rhs`
## Exception safety ## Exception safety
No-throw guarantee: this function never throws exceptions. 1. No-throw guarantee: this function never throws exceptions.
2. No-throw guarantee if converting the scalar to a JSON value cannot throw, as for numbers, Booleans, and
`#!cpp nullptr`; the function is `#!cpp noexcept` exactly in that case. Otherwise, it throws what the conversion
throws, for example `std::bad_alloc` when converting a string, or
[`out_of_range.410`](../../home/exceptions.md#jsonexceptionout_of_range410) for an enum value not mapped by
[`NLOHMANN_JSON_SERIALIZE_ENUM_STRICT`](../macros/nlohmann_json_serialize_enum_strict.md).
## Complexity ## Complexity
@@ -95,3 +100,4 @@ Linear.
1. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0. 1. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0.
2. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0. 2. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0.
Made conditionally `#!cpp noexcept` in version 3.13.0; before, a throwing conversion called `std::terminate`.
+4 -4
View File
@@ -2,11 +2,11 @@
<span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&lt;=</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (1)</span> <span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&lt;=</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (1)</span>
<span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span> <span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span>
<span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&lt;=</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>ScalarType</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (2)</span> <span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&lt;=</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>ScalarType</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>(</span><span class=cm>/* see below */</span><span class=p>);</span><span class=w> </span><span class=c1>// (2)</span>
<span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span> <span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span>
<span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&lt;=</span><span class=p>(</span><span class=n>ScalarType</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (2)</span> <span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&lt;=</span><span class=p>(</span><span class=n>ScalarType</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>(</span><span class=cm>/* see below */</span><span class=p>);</span><span class=w> </span><span class=c1>// (2)</span>
</code></pre></div> <ol> <li> <p>Compares whether one <abbr title="JavaScript Object Notation">JSON</abbr> value <code>lhs</code> is less than or equal to another <abbr title="JavaScript Object Notation">JSON</abbr> value <code>rhs</code> according to the following rules:</p> <ul> <li>The comparison always yields <code class=highlight><span class=nb>false</span></code> if (1) either operand is discarded, or (2) either operand is <code>NaN</code> and the other operand is either <code>NaN</code> or any other number.</li> <li>Otherwise, returns the result of <code class=highlight><span class=o>!</span><span class=p>(</span><span class=n>rhs</span><span class=w> </span><span class=o>&lt;</span><span class=w> </span><span class=n>lhs</span><span class=p>)</span></code> (see <a href=../operator_lt/ ><strong>operator&lt;</strong></a>).</li> </ul> </li> <li> <p>Compares whether a <abbr title="JavaScript Object Notation">JSON</abbr> value is less than or equal to a scalar or a scalar is less than or equal to a <abbr title="JavaScript Object Notation">JSON</abbr> value by converting the scalar to a <abbr title="JavaScript Object Notation">JSON</abbr> value and comparing both <abbr title="JavaScript Object Notation">JSON</abbr> values according to 1.</p> </li> </ol> <h2 id=template-parameters>Template parameters<a class=headerlink href=#template-parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>ScalarType</code></dt> <dd>a scalar type according to <code>std::is_scalar&lt;ScalarType&gt;::value</code></dd> </dl> <h2 id=parameters>Parameters<a class=headerlink href=#parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>lhs</code> (in)</dt> <dd>first value to consider </dd> <dt><code>rhs</code> (in)</dt> <dd>second value to consider </dd> </dl> <h2 id=return-value>Return value<a class=headerlink href=#return-value title="Permanent link">&para;</a></h2> <p>whether <code>lhs</code> is less than or equal to <code>rhs</code></p> <h2 id=exception-safety>Exception safety<a class=headerlink href=#exception-safety title="Permanent link">&para;</a></h2> <p>No-throw guarantee: this function never throws exceptions.</p> <h2 id=complexity>Complexity<a class=headerlink href=#complexity title="Permanent link">&para;</a></h2> <p>Linear.</p> <h2 id=notes>Notes<a class=headerlink href=#notes title="Permanent link">&para;</a></h2> <div class="admonition note"> <p class=admonition-title>Comparing <code>NaN</code></p> <p><code>NaN</code> values are unordered within the domain of numbers. The following comparisons all yield <code class=highlight><span class=nb>false</span></code>: 1. Comparing a <code>NaN</code> with itself. 2. Comparing a <code>NaN</code> with another <code>NaN</code>. 3. Comparing a <code>NaN</code> and any other number.</p> </div> <div class="admonition note"> <p class=admonition-title>Operator overload resolution</p> <p>Since C++20 overload resolution will consider the <em>rewritten candidate</em> generated from <a href=../operator_spaceship/ ><code>operator&lt;=&gt;</code></a>.</p> </div> <div class="admonition warning"> <p class=admonition-title>Deprecation</p> <p>If <a href=../../macros/json_use_legacy_discarded_value_comparison/ ><code>JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON</code></a> is defined to <code>1</code>, the library declares a member <code class=highlight><span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&lt;=</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=k>noexcept</span></code> in C++20 mode to emulate the legacy comparison of discarded values. This member is deprecated since version 3.11.0, together with the legacy comparison behavior.</p> <p>See the <a href=../../../integration/migration_guide/#miscellaneous-functions>migration guide</a> for how to update existing code.</p> </div> <h2 id=examples>Examples<a class=headerlink href=#examples title="Permanent link">&para;</a></h2> <details class=example> <summary>Example</summary> <p>The example demonstrates comparing several <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class=highlight><pre><span></span><code><span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;iostream&gt;</span> </code></pre></div> <ol> <li> <p>Compares whether one <abbr title="JavaScript Object Notation">JSON</abbr> value <code>lhs</code> is less than or equal to another <abbr title="JavaScript Object Notation">JSON</abbr> value <code>rhs</code> according to the following rules:</p> <ul> <li>The comparison always yields <code class=highlight><span class=nb>false</span></code> if (1) either operand is discarded, or (2) either operand is <code>NaN</code> and the other operand is either <code>NaN</code> or any other number.</li> <li>Otherwise, returns the result of <code class=highlight><span class=o>!</span><span class=p>(</span><span class=n>rhs</span><span class=w> </span><span class=o>&lt;</span><span class=w> </span><span class=n>lhs</span><span class=p>)</span></code> (see <a href=../operator_lt/ ><strong>operator&lt;</strong></a>).</li> </ul> </li> <li> <p>Compares whether a <abbr title="JavaScript Object Notation">JSON</abbr> value is less than or equal to a scalar or a scalar is less than or equal to a <abbr title="JavaScript Object Notation">JSON</abbr> value by converting the scalar to a <abbr title="JavaScript Object Notation">JSON</abbr> value and comparing both <abbr title="JavaScript Object Notation">JSON</abbr> values according to 1.</p> </li> </ol> <h2 id=template-parameters>Template parameters<a class=headerlink href=#template-parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>ScalarType</code></dt> <dd>a scalar type according to <code>std::is_scalar&lt;ScalarType&gt;::value</code></dd> </dl> <h2 id=parameters>Parameters<a class=headerlink href=#parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>lhs</code> (in)</dt> <dd>first value to consider </dd> <dt><code>rhs</code> (in)</dt> <dd>second value to consider </dd> </dl> <h2 id=return-value>Return value<a class=headerlink href=#return-value title="Permanent link">&para;</a></h2> <p>whether <code>lhs</code> is less than or equal to <code>rhs</code></p> <h2 id=exception-safety>Exception safety<a class=headerlink href=#exception-safety title="Permanent link">&para;</a></h2> <ol> <li>No-throw guarantee: this function never throws exceptions.</li> <li>No-throw guarantee if converting the scalar to a <abbr title="JavaScript Object Notation">JSON</abbr> value cannot throw, as for numbers, Booleans, and <code class=highlight><span class=nb>nullptr</span></code>; the function is <code class=highlight><span class=k>noexcept</span></code> exactly in that case. Otherwise, it throws what the conversion throws, for example <code>std::bad_alloc</code> when converting a string, or <a href=../../../home/exceptions/#jsonexceptionout_of_range410><code>out_of_range.410</code></a> for an enum value not mapped by <a href=../../macros/nlohmann_json_serialize_enum_strict/ ><code>NLOHMANN_JSON_SERIALIZE_ENUM_STRICT</code></a>.</li> </ol> <h2 id=complexity>Complexity<a class=headerlink href=#complexity title="Permanent link">&para;</a></h2> <p>Linear.</p> <h2 id=notes>Notes<a class=headerlink href=#notes title="Permanent link">&para;</a></h2> <div class="admonition note"> <p class=admonition-title>Comparing <code>NaN</code></p> <p><code>NaN</code> values are unordered within the domain of numbers. The following comparisons all yield <code class=highlight><span class=nb>false</span></code>: 1. Comparing a <code>NaN</code> with itself. 2. Comparing a <code>NaN</code> with another <code>NaN</code>. 3. Comparing a <code>NaN</code> and any other number.</p> </div> <div class="admonition note"> <p class=admonition-title>Operator overload resolution</p> <p>Since C++20 overload resolution will consider the <em>rewritten candidate</em> generated from <a href=../operator_spaceship/ ><code>operator&lt;=&gt;</code></a>.</p> </div> <div class="admonition warning"> <p class=admonition-title>Deprecation</p> <p>If <a href=../../macros/json_use_legacy_discarded_value_comparison/ ><code>JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON</code></a> is defined to <code>1</code>, the library declares a member <code class=highlight><span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&lt;=</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=k>noexcept</span></code> in C++20 mode to emulate the legacy comparison of discarded values. This member is deprecated since version 3.11.0, together with the legacy comparison behavior.</p> <p>See the <a href=../../../integration/migration_guide/#miscellaneous-functions>migration guide</a> for how to update existing code.</p> </div> <h2 id=examples>Examples<a class=headerlink href=#examples title="Permanent link">&para;</a></h2> <details class=example> <summary>Example</summary> <p>The example demonstrates comparing several <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class=highlight><pre><span></span><code><span class=Line truncated
<span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;nlohmann/json.hpp&gt;</span> <span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;nlohmann/json.hpp&gt;</span>
<span class=k>using</span><span class=w> </span><span class=n>json</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=n>nlohmann</span><span class=o>::</span><span class=n>json</span><span class=p>;</span> <span class=k>using</span><span class=w> </span><span class=n>json</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=n>nlohmann</span><span class=o>::</span><span class=n>json</span><span class=p>;</span>
@@ -34,4 +34,4 @@
<span class=p>{</span><span class=nt>"A"</span><span class=p>:</span><span class=s2>"a"</span><span class=p>,</span><span class=nt>"B"</span><span class=p>:</span><span class=s2>"b"</span><span class=p>}</span><span class=w> </span><span class=err>&lt;=</span><span class=w> </span><span class=p>{</span><span class=nt>"A"</span><span class=p>:</span><span class=s2>"a"</span><span class=p>,</span><span class=nt>"B"</span><span class=p>:</span><span class=s2>"b"</span><span class=p>}</span><span class=w> </span><span class=kc>true</span> <span class=p>{</span><span class=nt>"A"</span><span class=p>:</span><span class=s2>"a"</span><span class=p>,</span><span class=nt>"B"</span><span class=p>:</span><span class=s2>"b"</span><span class=p>}</span><span class=w> </span><span class=err>&lt;=</span><span class=w> </span><span class=p>{</span><span class=nt>"A"</span><span class=p>:</span><span class=s2>"a"</span><span class=p>,</span><span class=nt>"B"</span><span class=p>:</span><span class=s2>"b"</span><span class=p>}</span><span class=w> </span><span class=kc>true</span>
<span class=mi>17</span><span class=w> </span><span class=err>&lt;=</span><span class=w> </span><span class=mf>17.0000000000001</span><span class=w> </span><span class=kc>true</span> <span class=mi>17</span><span class=w> </span><span class=err>&lt;=</span><span class=w> </span><span class=mf>17.0000000000001</span><span class=w> </span><span class=kc>true</span>
<span class=s2>"foo"</span><span class=w> </span><span class=err>&lt;=</span><span class=w> </span><span class=s2>"bar"</span><span class=w> </span><span class=kc>false</span> <span class=s2>"foo"</span><span class=w> </span><span class=err>&lt;=</span><span class=w> </span><span class=s2>"bar"</span><span class=w> </span><span class=kc>false</span>
</code></pre></div> </details> <h2 id=see-also>See also<a class=headerlink href=#see-also title="Permanent link">&para;</a></h2> <ul> <li><a href=../operator_spaceship/ ><strong>operator&lt;=&gt;</strong></a> comparison: 3-way</li> </ul> <h2 id=version-history>Version history<a class=headerlink href=#version-history title="Permanent link">&para;</a></h2> <ol> <li>Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0.</li> <li>Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0.</li> </ol> <!-- https://squidfunk.github.io/mkdocs-material/reference/tooltips/#adding-a-glossary --> <aside class=md-source-file> <span class=md-source-file__fact> <span class=md-icon title="Last update"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1zM12.5 7v5.2l4 2.4-1 1L11 13V7zM11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2z"/></svg> </span> <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date" title="October 2, 2026 09:32:15 UTC">October 2, 2026</span> </span> </aside> </article> </div> <script>var tabs=__md_get("__tabs");if(Array.isArray(tabs))e:for(var set of document.querySelectorAll(".tabbed-set")){var labels=set.querySelector(".tabbed-labels");for(var tab of tabs)for(var label of labels.getElementsByTagName("label"))if(label.innerText.trim()===tab){var input=document.getElementById(label.htmlFor);input.checked=!0;continue e}}</script> <script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script> </div> <button type=button class="md-top md-icon" data-md-component=top hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z"/></svg> Back to top </button> </main> <footer class=md-footer> <div class="md-footer-meta md-typeset"> <div class="md-footer-meta__inner md-grid"> <div class=md-copyright> <div class=md-copyright__highlight> Copyright &copy; 2013-2026 Niels Lohmann </div> </div> <div class=md-social> <a href="https://github.com/nlohmann" target="_blank" rel="noopener" title="github.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 512 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M173.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6m-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3m44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9M252.8 8C114.1 8 8 113.3 8 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C436.2 457.8 504 362.9 504 252 504 113.3 391.5 8 252.8 8M105.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1m-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7m32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1m-11.4-14.7c-1.6 1-1.6 3.6 0 5.9s4.3 3.3 5.6 2.3c1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2"/></svg> </a> <a href="https://www.linkedin.com/in/nielslohmann/" target="_blank" rel="noopener" title="www.linkedin.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 448 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M416 32H31.9C14.3 32 0 46.5 0 64.3v383.4C0 465.5 14.3 480 31.9 480H416c17.6 0 32-14.5 32-32.3V64.3c0-17.8-14.4-32.3-32-32.3M135.4 416H69V202.2h66.5V416zM102.2 96a38.5 38.5 0 1 1 0 77 38.5 38.5 0 1 1 0-77m282.1 320h-66.4V312c0-24.8-.5-56.7-34.5-56.7-34.6 0-39.9 27-39.9 54.9V416h-66.4V202.2h63.7v29.2h.9c8.9-16.8 30.6-34.5 62.9-34.5 67.2 0 79.7 44.3 79.7 101.9z"/></svg> </a> <a href="https://www.xing.com/profile/Niels_Lohmann" target="_blank" rel="noopener" title="www.xing.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 384 512"><!-- FontLine truncated </code></pre></div> </details> <h2 id=see-also>See also<a class=headerlink href=#see-also title="Permanent link">&para;</a></h2> <ul> <li><a href=../operator_spaceship/ ><strong>operator&lt;=&gt;</strong></a> comparison: 3-way</li> </ul> <h2 id=version-history>Version history<a class=headerlink href=#version-history title="Permanent link">&para;</a></h2> <ol> <li>Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0.</li> <li>Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0. Made conditionally <code class=highlight><span class=k>noexcept</span></code> in version 3.13.0 <span class=unreleased-version title="Not part of a release yet; the latest release is 3.12.0.">unreleased</span>; before, a throwing conversion called <code>std::terminate</code>.</li> </ol> <!-- https://squidfunk.github.io/mkdocs-material/reference/tooltips/#adding-a-glossary --> <aside class=md-source-file> <span class=md-source-file__fact> <span class=md-icon title="Last update"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1zM12.5 7v5.2l4 2.4-1 1L11 13V7zM11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2z"/></svg> </span> <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date" title="October 2, 2026 15:25:17 UTC">October 2, 2026</span> </span> </aside> </article> </div> <script>var tabs=__md_get("__tabs");if(Array.isArray(tabs))e:for(var set of document.querySelectorAll(".tabbed-set")){var labels=set.querySelector(".tabbed-labels");for(var tab of tabs)for(var label of labels.getElementsByTagName("label"))if(label.innerText.trim()===tab){var input=document.getElementById(label.htmlFor);input.checked=!0;continue e}}</script> <script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script> </div> <button type=button class="md-top md-icon" data-md-component=top hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z"/></svg> Back to top </button> </main> <footer class=md-footer> <div class="md-footer-meta md-typeset"> <div class="md-footer-meta__inner md-grid"> <div class=md-copyright> <div class=md-copyright__highlight> Copyright &copy; 2013-2026 Niels Lohmann </div> </div> <div class=md-social> <a href="https://github.com/nlohmann" target="_blank" rel="noopener" title="github.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 512 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M173.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6m-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3m44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9M252.8 8C114.1 8 8 113.3 8 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C436.2 457.8 504 362.9 504 252 504 113.3 391.5 8 252.8 8M105.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1m-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7m32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1m-11.4-14.7c-1.6 1-1.6 3.6 0 5.9s4.3 3.3 5.6 2.3c1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2"/></svg> </a> <a href="https://www.linkedin.com/in/nielslohmann/" target="_blank" rel="noopener" title="www.linkedin.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 448 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M416 32H31.9C14.3 32 0 46.5 0 64.3v383.4C0 465.5 14.3 480 31.9 480H416c17.6 0 32-14.5 32-32.3V64.3c0-17.8-14.4-32.3-32-32.3M135.4 416H69V202.2h66.5V416zM102.2 96a38.5 38.5 0 1 1 0 77 38.5 38.5 0 1 1 0-77m282.1 320h-66.4V312c0-24.8-.5-56.7-34.5-56.7-34.6 0-39.9 27-39.9 54.9V416h-66.4V202.2h63.7v29Line truncated
+5 -4
View File
@@ -5,10 +5,10 @@
bool operator<=(const_reference lhs, const_reference rhs) noexcept; // (1) bool operator<=(const_reference lhs, const_reference rhs) noexcept; // (1)
template<typename ScalarType> template<typename ScalarType>
bool operator<=(const_reference lhs, const ScalarType rhs) noexcept; // (2) bool operator<=(const_reference lhs, const ScalarType rhs) noexcept(/* see below */); // (2)
template<typename ScalarType> template<typename ScalarType>
bool operator<=(ScalarType lhs, const const_reference rhs) noexcept; // (2) bool operator<=(ScalarType lhs, const const_reference rhs) noexcept(/* see below */); // (2)
``` ```
1. Compares whether one JSON value `lhs` is less than or equal to another JSON value `rhs` according to the following rules: 1. Compares whether one JSON value `lhs` is less than or equal to another JSON value `rhs` according to the following rules:
@@ -34,7 +34,8 @@ whether `lhs` is less than or equal to `rhs`
## Exception safety ## Exception safety
No-throw guarantee: this function never throws exceptions. 1. No-throw guarantee: this function never throws exceptions.
1. No-throw guarantee if converting the scalar to a JSON value cannot throw, as for numbers, Booleans, and `nullptr`; the function is `noexcept` exactly in that case. Otherwise, it throws what the conversion throws, for example `std::bad_alloc` when converting a string, or [`out_of_range.410`](https://json.nlohmann.me/home/exceptions/#jsonexceptionout_of_range410) for an enum value not mapped by [`NLOHMANN_JSON_SERIALIZE_ENUM_STRICT`](https://json.nlohmann.me/api/macros/nlohmann_json_serialize_enum_strict/index.md).
## Complexity ## Complexity
@@ -109,4 +110,4 @@ Output:
## Version history ## Version history
1. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0. 1. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0.
1. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0. 1. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0. Made conditionally `noexcept` in version 3.13.0 unreleased; before, a throwing conversion called `std::terminate`.
+9 -3
View File
@@ -5,10 +5,10 @@
bool operator<(const_reference lhs, const_reference rhs) noexcept; // (1) bool operator<(const_reference lhs, const_reference rhs) noexcept; // (1)
template<typename ScalarType> template<typename ScalarType>
bool operator<(const_reference lhs, const ScalarType rhs) noexcept; // (2) bool operator<(const_reference lhs, const ScalarType rhs) noexcept(/* see below */); // (2)
template<typename ScalarType> template<typename ScalarType>
bool operator<(ScalarType lhs, const const_reference rhs) noexcept; // (2) bool operator<(ScalarType lhs, const const_reference rhs) noexcept(/* see below */); // (2)
``` ```
1. Compares whether one JSON value `lhs` is less than another JSON value `rhs` according to the 1. Compares whether one JSON value `lhs` is less than another JSON value `rhs` according to the
@@ -49,7 +49,12 @@ whether `lhs` is less than `rhs`
## Exception safety ## Exception safety
No-throw guarantee: this function never throws exceptions. 1. No-throw guarantee: this function never throws exceptions.
2. No-throw guarantee if converting the scalar to a JSON value cannot throw, as for numbers, Booleans, and
`#!cpp nullptr`; the function is `#!cpp noexcept` exactly in that case. Otherwise, it throws what the conversion
throws, for example `std::bad_alloc` when converting a string, or
[`out_of_range.410`](../../home/exceptions.md#jsonexceptionout_of_range410) for an enum value not mapped by
[`NLOHMANN_JSON_SERIALIZE_ENUM_STRICT`](../macros/nlohmann_json_serialize_enum_strict.md).
## Complexity ## Complexity
@@ -94,3 +99,4 @@ Linear.
1. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0. 1. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0.
2. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0. 2. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0.
Made conditionally `#!cpp noexcept` in version 3.13.0; before, a throwing conversion called `std::terminate`.
+4 -4
View File
@@ -2,11 +2,11 @@
<span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&lt;</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (1)</span> <span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&lt;</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (1)</span>
<span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span> <span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span>
<span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&lt;</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>ScalarType</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (2)</span> <span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&lt;</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>ScalarType</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>(</span><span class=cm>/* see below */</span><span class=p>);</span><span class=w> </span><span class=c1>// (2)</span>
<span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span> <span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span>
<span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&lt;</span><span class=p>(</span><span class=n>ScalarType</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (2)</span> <span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>&lt;</span><span class=p>(</span><span class=n>ScalarType</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>(</span><span class=cm>/* see below */</span><span class=p>);</span><span class=w> </span><span class=c1>// (2)</span>
</code></pre></div> <ol> <li> <p>Compares whether one <abbr title="JavaScript Object Notation">JSON</abbr> value <code>lhs</code> is less than another <abbr title="JavaScript Object Notation">JSON</abbr> value <code>rhs</code> according to the following rules:</p> <ul> <li>If either operand is discarded, the comparison yields <code class=highlight><span class=nb>false</span></code>.</li> <li>If both operands have the same type, the values are compared using their respective <code>operator&lt;</code>.</li> <li>Integer and floating-point numbers are automatically converted before comparison.</li> <li>In case <code>lhs</code> and <code>rhs</code> have different types, the values are ignored and the order of the types is considered, which is:<ol> <li>null</li> <li>boolean</li> <li>number (all types)</li> <li>object</li> <li>array</li> <li>string</li> <li>binary For instance, any boolean value is considered less than any string.</li> </ol> </li> </ul> </li> <li> <p>Compares whether a <abbr title="JavaScript Object Notation">JSON</abbr> value is less than a scalar or a scalar is less than a <abbr title="JavaScript Object Notation">JSON</abbr> value by converting the scalar to a <abbr title="JavaScript Object Notation">JSON</abbr> value and comparing both <abbr title="JavaScript Object Notation">JSON</abbr> values according to 1.</p> </li> </ol> <h2 id=template-parameters>Template parameters<a class=headerlink href=#template-parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>ScalarType</code></dt> <dd>a scalar type according to <code>std::is_scalar&lt;ScalarType&gt;::value</code></dd> </dl> <h2 id=parameters>Parameters<a class=headerlink href=#parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>lhs</code> (in)</dt> <dd>first value to consider </dd> <dt><code>rhs</code> (in)</dt> <dd>second value to consider </dd> </dl> <h2 id=return-value>Return value<a class=headerlink href=#return-value title="Permanent link">&para;</a></h2> <p>whether <code>lhs</code> is less than <code>rhs</code></p> <h2 id=exception-safety>Exception safety<a class=headerlink href=#exception-safety title="Permanent link">&para;</a></h2> <p>No-throw guarantee: this function never throws exceptions.</p> <h2 id=complexity>Complexity<a class=headerlink href=#complexity title="Permanent link">&para;</a></h2> <p>Linear.</p> <h2 id=notes>Notes<a class=headerlink href=#notes title="Permanent link">&para;</a></h2> <div class="admonition note"> <p class=admonition-title>Comparing <code>NaN</code></p> <p><code>NaN</code> values are unordered within the domain of numbers. The following comparisons all yield <code class=highlight><span class=nb>false</span></code>: 1. Comparing a <code>NaN</code> with itself. 2. Comparing a <code>NaN</code> with another <code>NaN</code>. 3. Comparing a <code>NaN</code> and any other number.</p> </div> <div class="admonition note"> <p class=admonition-title>Operator overload resolution</p> <p>Since C++20 overload resolution will consider the <em>rewritten candidate</em> generated from <a href=../operator_spaceship/ ><code>operator&lt;=&gt;</code></a>.</p> </div> <h2 id=examples>Examples<a class=headerlink href=#examples title="Permanent link">&para;</a></h2> <details class=example> <summary>Example</summary> <p>The example demonstrates comparing several <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class=highlight><pre><span></span><code><span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;iostream&gt;</span> </code></pre></div> <ol> <li> <p>Compares whether one <abbr title="JavaScript Object Notation">JSON</abbr> value <code>lhs</code> is less than another <abbr title="JavaScript Object Notation">JSON</abbr> value <code>rhs</code> according to the following rules:</p> <ul> <li>If either operand is discarded, the comparison yields <code class=highlight><span class=nb>false</span></code>.</li> <li>If both operands have the same type, the values are compared using their respective <code>operator&lt;</code>.</li> <li>Integer and floating-point numbers are automatically converted before comparison.</li> <li>In case <code>lhs</code> and <code>rhs</code> have different types, the values are ignored and the order of the types is considered, which is:<ol> <li>null</li> <li>boolean</li> <li>number (all types)</li> <li>object</li> <li>array</li> <li>string</li> <li>binary For instance, any boolean value is considered less than any string.</li> </ol> </li> </ul> </li> <li> <p>Compares whether a <abbr title="JavaScript Object Notation">JSON</abbr> value is less than a scalar or a scalar is less than a <abbr title="JavaScript Object Notation">JSON</abbr> value by converting the scalar to a <abbr title="JavaScript Object Notation">JSON</abbr> value and comparing both <abbr title="JavaScript Object Notation">JSON</abbr> values according to 1.</p> </li> </ol> <h2 id=template-parameters>Template parameters<a class=headerlink href=#template-parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>ScalarType</code></dt> <dd>a scalar type according to <code>std::is_scalar&lt;ScalarType&gt;::value</code></dd> </dl> <h2 id=parameters>Parameters<a class=headerlink href=#parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>lhs</code> (in)</dt> <dd>first value to consider </dd> <dt><code>rhs</code> (in)</dt> <dd>second value to consider </dd> </dl> <h2 id=return-value>Return value<a class=headerlink href=#return-value title="Permanent link">&para;</a></h2> <p>whether <code>lhs</code> is less than <code>rhs</code></p> <h2 id=exception-safety>Exception safety<a class=headerlink href=#exception-safety title="Permanent link">&para;</a></h2> <ol> <li>No-throw guarantee: this function never throws exceptions.</li> <li>No-throw guarantee if converting the scalar to a <abbr title="JavaScript Object Notation">JSON</abbr> value cannot throw, as for numbers, Booleans, and <code class=highlight><span class=nb>nullptr</span></code>; the function is <code class=highlight><span class=k>noexcept</span></code> exactly in that case. Otherwise, it throws what the conversion throws, for example <code>std::bad_alloc</code> when converting a string, or <a href=../../../home/exceptions/#jsonexceptionout_of_range410><code>out_of_range.410</code></a> for an enum value not mapped by <a href=../../macros/nlohmann_json_serialize_enum_strict/ ><code>NLOHMANN_JSON_SERIALIZE_ENUM_STRICT</code></a>.</li> </ol> <h2 id=complexity>Complexity<a class=headerlink href=#complexity title="Permanent link">&para;</a></h2> <p>Linear.</p> <h2 id=notes>Notes<a class=headerlink href=#notes title="Permanent link">&para;</a></h2> <div class="admonition note"> <p class=admonition-title>Comparing <code>NaN</code></p> <p><code>NaN</code> values are unordered within the domain of numbers. The following comparisons all yield <code class=highlight><span class=nb>false</span></code>: 1. Comparing a <code>NaN</code> with itself. 2. Comparing a <code>NaN</code> with another <code>NaN</code>. 3. Comparing a <code>NaN</code> and any other number.</p> </div> <div class="admonition note"> <p class=admonition-title>Operator overload resolution</p> <p>Since C++20 overload resolution will consider the <em>rewritten candidate</em> generated from <a href=../operator_spaceship/ ><code>operator&lt;=&gt;</code></a>.</p> </div> <h2 id=examples>Examples<a class=headerlink href=#examples title="Permanent link">&para;</a></h2> <details class=example> <summary>Example</summary> <p>The example demonstrates comparing several <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class=highlight><pre><span></span><code><span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;iostream&gt;</span>
<span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;nlohmann/json.hpp&gt;</span> <span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;nlohmann/json.hpp&gt;</span>
<span class=k>using</span><span class=w> </span><span class=n>json</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=n>nlohmann</span><span class=o>::</span><span class=n>json</span><span class=p>;</span> <span class=k>using</span><span class=w> </span><span class=n>json</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=n>nlohmann</span><span class=o>::</span><span class=n>json</span><span class=p>;</span>
@@ -34,4 +34,4 @@
<span class=p>{</span><span class=nt>"A"</span><span class=p>:</span><span class=s2>"a"</span><span class=p>,</span><span class=nt>"B"</span><span class=p>:</span><span class=s2>"b"</span><span class=p>}</span><span class=w> </span><span class=err>==</span><span class=w> </span><span class=p>{</span><span class=nt>"A"</span><span class=p>:</span><span class=s2>"a"</span><span class=p>,</span><span class=nt>"B"</span><span class=p>:</span><span class=s2>"b"</span><span class=p>}</span><span class=w> </span><span class=kc>false</span> <span class=p>{</span><span class=nt>"A"</span><span class=p>:</span><span class=s2>"a"</span><span class=p>,</span><span class=nt>"B"</span><span class=p>:</span><span class=s2>"b"</span><span class=p>}</span><span class=w> </span><span class=err>==</span><span class=w> </span><span class=p>{</span><span class=nt>"A"</span><span class=p>:</span><span class=s2>"a"</span><span class=p>,</span><span class=nt>"B"</span><span class=p>:</span><span class=s2>"b"</span><span class=p>}</span><span class=w> </span><span class=kc>false</span>
<span class=mi>17</span><span class=w> </span><span class=err>==</span><span class=w> </span><span class=mf>17.0000000000001</span><span class=w> </span><span class=kc>true</span> <span class=mi>17</span><span class=w> </span><span class=err>==</span><span class=w> </span><span class=mf>17.0000000000001</span><span class=w> </span><span class=kc>true</span>
<span class=s2>"foo"</span><span class=w> </span><span class=err>==</span><span class=w> </span><span class=s2>"bar"</span><span class=w> </span><span class=kc>false</span> <span class=s2>"foo"</span><span class=w> </span><span class=err>==</span><span class=w> </span><span class=s2>"bar"</span><span class=w> </span><span class=kc>false</span>
</code></pre></div> </details> <h2 id=see-also>See also<a class=headerlink href=#see-also title="Permanent link">&para;</a></h2> <ul> <li><a href=../operator_spaceship/ ><strong>operator&lt;=&gt;</strong></a> comparison: 3-way</li> </ul> <h2 id=version-history>Version history<a class=headerlink href=#version-history title="Permanent link">&para;</a></h2> <ol> <li>Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0.</li> <li>Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0.</li> </ol> <!-- https://squidfunk.github.io/mkdocs-material/reference/tooltips/#adding-a-glossary --> <aside class=md-source-file> <span class=md-source-file__fact> <span class=md-icon title="Last update"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1zM12.5 7v5.2l4 2.4-1 1L11 13V7zM11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2z"/></svg> </span> <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date" title="July 7, 2024 08:22:17 UTC">July 7, 2024</span> </span> </aside> </article> </div> <script>var tabs=__md_get("__tabs");if(Array.isArray(tabs))e:for(var set of document.querySelectorAll(".tabbed-set")){var labels=set.querySelector(".tabbed-labels");for(var tab of tabs)for(var label of labels.getElementsByTagName("label"))if(label.innerText.trim()===tab){var input=document.getElementById(label.htmlFor);input.checked=!0;continue e}}</script> <script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script> </div> <button type=button class="md-top md-icon" data-md-component=top hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z"/></svg> Back to top </button> </main> <footer class=md-footer> <div class="md-footer-meta md-typeset"> <div class="md-footer-meta__inner md-grid"> <div class=md-copyright> <div class=md-copyright__highlight> Copyright &copy; 2013-2026 Niels Lohmann </div> </div> <div class=md-social> <a href="https://github.com/nlohmann" target="_blank" rel="noopener" title="github.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 512 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M173.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6m-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3m44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9M252.8 8C114.1 8 8 113.3 8 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C436.2 457.8 504 362.9 504 252 504 113.3 391.5 8 252.8 8M105.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1m-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7m32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1m-11.4-14.7c-1.6 1-1.6 3.6 0 5.9s4.3 3.3 5.6 2.3c1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2"/></svg> </a> <a href="https://www.linkedin.com/in/nielslohmann/" target="_blank" rel="noopener" title="www.linkedin.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 448 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M416 32H31.9C14.3 32 0 46.5 0 64.3v383.4C0 465.5 14.3 480 31.9 480H416c17.6 0 32-14.5 32-32.3V64.3c0-17.8-14.4-32.3-32-32.3M135.4 416H69V202.2h66.5V416zM102.2 96a38.5 38.5 0 1 1 0 77 38.5 38.5 0 1 1 0-77m282.1 320h-66.4V312c0-24.8-.5-56.7-34.5-56.7-34.6 0-39.9 27-39.9 54.9V416h-66.4V202.2h63.7v29.2h.9c8.9-16.8 30.6-34.5 62.9-34.5 67.2 0 79.7 44.3 79.7 101.9z"/></svg> </a> <a href="https://www.xing.com/profile/Niels_Lohmann" target="_blank" rel="noopener" title="www.xing.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 384 512"><!-- Font AwesoLine truncated </code></pre></div> </details> <h2 id=see-also>See also<a class=headerlink href=#see-also title="Permanent link">&para;</a></h2> <ul> <li><a href=../operator_spaceship/ ><strong>operator&lt;=&gt;</strong></a> comparison: 3-way</li> </ul> <h2 id=version-history>Version history<a class=headerlink href=#version-history title="Permanent link">&para;</a></h2> <ol> <li>Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0.</li> <li>Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0. Made conditionally <code class=highlight><span class=k>noexcept</span></code> in version 3.13.0 <span class=unreleased-version title="Not part of a release yet; the latest release is 3.12.0.">unreleased</span>; before, a throwing conversion called <code>std::terminate</code>.</li> </ol> <!-- https://squidfunk.github.io/mkdocs-material/reference/tooltips/#adding-a-glossary --> <aside class=md-source-file> <span class=md-source-file__fact> <span class=md-icon title="Last update"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1zM12.5 7v5.2l4 2.4-1 1L11 13V7zM11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2z"/></svg> </span> <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date" title="October 2, 2026 15:25:17 UTC">October 2, 2026</span> </span> </aside> </article> </div> <script>var tabs=__md_get("__tabs");if(Array.isArray(tabs))e:for(var set of document.querySelectorAll(".tabbed-set")){var labels=set.querySelector(".tabbed-labels");for(var tab of tabs)for(var label of labels.getElementsByTagName("label"))if(label.innerText.trim()===tab){var input=document.getElementById(label.htmlFor);input.checked=!0;continue e}}</script> <script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script> </div> <button type=button class="md-top md-icon" data-md-component=top hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z"/></svg> Back to top </button> </main> <footer class=md-footer> <div class="md-footer-meta md-typeset"> <div class="md-footer-meta__inner md-grid"> <div class=md-copyright> <div class=md-copyright__highlight> Copyright &copy; 2013-2026 Niels Lohmann </div> </div> <div class=md-social> <a href="https://github.com/nlohmann" target="_blank" rel="noopener" title="github.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 512 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M173.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6m-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3m44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9M252.8 8C114.1 8 8 113.3 8 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C436.2 457.8 504 362.9 504 252 504 113.3 391.5 8 252.8 8M105.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1m-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7m32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1m-11.4-14.7c-1.6 1-1.6 3.6 0 5.9s4.3 3.3 5.6 2.3c1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2"/></svg> </a> <a href="https://www.linkedin.com/in/nielslohmann/" target="_blank" rel="noopener" title="www.linkedin.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 448 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M416 32H31.9C14.3 32 0 46.5 0 64.3v383.4C0 465.5 14.3 480 31.9 480H416c17.6 0 32-14.5 32-32.3V64.3c0-17.8-14.4-32.3-32-32.3M135.4 416H69V202.2h66.5V416zM102.2 96a38.5 38.5 0 1 1 0 77 38.5 38.5 0 1 1 0-77m282.1 320h-66.4V312c0-24.8-.5-56.7-34.5-56.7-34.6 0-39.9 27-39.9 54.9V416h-66.4V202.2h63.7v29Line truncated
+5 -4
View File
@@ -5,10 +5,10 @@
bool operator<(const_reference lhs, const_reference rhs) noexcept; // (1) bool operator<(const_reference lhs, const_reference rhs) noexcept; // (1)
template<typename ScalarType> template<typename ScalarType>
bool operator<(const_reference lhs, const ScalarType rhs) noexcept; // (2) bool operator<(const_reference lhs, const ScalarType rhs) noexcept(/* see below */); // (2)
template<typename ScalarType> template<typename ScalarType>
bool operator<(ScalarType lhs, const const_reference rhs) noexcept; // (2) bool operator<(ScalarType lhs, const const_reference rhs) noexcept(/* see below */); // (2)
``` ```
1. Compares whether one JSON value `lhs` is less than another JSON value `rhs` according to the following rules: 1. Compares whether one JSON value `lhs` is less than another JSON value `rhs` according to the following rules:
@@ -43,7 +43,8 @@ whether `lhs` is less than `rhs`
## Exception safety ## Exception safety
No-throw guarantee: this function never throws exceptions. 1. No-throw guarantee: this function never throws exceptions.
1. No-throw guarantee if converting the scalar to a JSON value cannot throw, as for numbers, Booleans, and `nullptr`; the function is `noexcept` exactly in that case. Otherwise, it throws what the conversion throws, for example `std::bad_alloc` when converting a string, or [`out_of_range.410`](https://json.nlohmann.me/home/exceptions/#jsonexceptionout_of_range410) for an enum value not mapped by [`NLOHMANN_JSON_SERIALIZE_ENUM_STRICT`](https://json.nlohmann.me/api/macros/nlohmann_json_serialize_enum_strict/index.md).
## Complexity ## Complexity
@@ -112,4 +113,4 @@ Output:
## Version history ## Version history
1. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0. 1. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0.
1. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0. 1. Added in version 1.0.0. Conditionally removed since C++20 in version 3.11.0. Made conditionally `noexcept` in version 3.13.0 unreleased; before, a throwing conversion called `std::terminate`.
+9 -3
View File
@@ -5,10 +5,10 @@
bool operator!=(const_reference lhs, const_reference rhs) noexcept; // (1) bool operator!=(const_reference lhs, const_reference rhs) noexcept; // (1)
template<typename ScalarType> template<typename ScalarType>
bool operator!=(const_reference lhs, const ScalarType rhs) noexcept; // (2) bool operator!=(const_reference lhs, const ScalarType rhs) noexcept(/* see below */); // (2)
template<typename ScalarType> template<typename ScalarType>
bool operator!=(ScalarType lhs, const const_reference rhs) noexcept; // (2) bool operator!=(ScalarType lhs, const const_reference rhs) noexcept(/* see below */); // (2)
``` ```
1. Compares two JSON values for inequality. Returns `#!cpp !(lhs == rhs)`. 1. Compares two JSON values for inequality. Returns `#!cpp !(lhs == rhs)`.
@@ -36,7 +36,12 @@ whether the values `lhs`/`*this` and `rhs` are not equal
## Exception safety ## Exception safety
No-throw guarantee: this function never throws exceptions. 1. No-throw guarantee: this function never throws exceptions.
2. No-throw guarantee if converting the scalar to a JSON value cannot throw, as for numbers, Booleans, and
`#!cpp nullptr`; the function is `#!cpp noexcept` exactly in that case. Otherwise, it throws what the conversion
throws, for example `std::bad_alloc` when converting a string, or
[`out_of_range.410`](../../home/exceptions.md#jsonexceptionout_of_range410) for an enum value not mapped by
[`NLOHMANN_JSON_SERIALIZE_ENUM_STRICT`](../macros/nlohmann_json_serialize_enum_strict.md).
## Complexity ## Complexity
@@ -98,3 +103,4 @@ Linear.
member function in version 3.13.0; since C++20, the compiler rewrites `a != b` using `operator==`. member function in version 3.13.0; since C++20, the compiler rewrites `a != b` using `operator==`.
2. Added in version 1.0.0. Changed in version 3.13.0 to remove special-casing for `NaN` and `discarded` values; 2. Added in version 1.0.0. Changed in version 3.13.0 to remove special-casing for `NaN` and `discarded` values;
`operator!=` now consistently means `!(a == b)`. Since C++20, the compiler rewrites `a != b` using `operator==`. `operator!=` now consistently means `!(a == b)`. Since C++20, the compiler rewrites `a != b` using `operator==`.
Made conditionally `#!cpp noexcept` in version 3.13.0; before, a throwing conversion called `std::terminate`.
+4 -4
View File
@@ -2,11 +2,11 @@
<span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>!=</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (1)</span> <span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>!=</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (1)</span>
<span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span> <span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span>
<span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>!=</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>ScalarType</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (2)</span> <span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>!=</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>ScalarType</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>(</span><span class=cm>/* see below */</span><span class=p>);</span><span class=w> </span><span class=c1>// (2)</span>
<span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span> <span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span>
<span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>!=</span><span class=p>(</span><span class=n>ScalarType</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (2)</span> <span class=kt>bool</span><span class=w> </span><span class=k>operator</span><span class=o>!=</span><span class=p>(</span><span class=n>ScalarType</span><span class=w> </span><span class=n>lhs</span><span class=p>,</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>noexcept</span><span class=p>(</span><span class=cm>/* see below */</span><span class=p>);</span><span class=w> </span><span class=c1>// (2)</span>
</code></pre></div> <ol> <li> <p>Compares two <abbr title="JavaScript Object Notation">JSON</abbr> values for inequality. Returns <code class=highlight><span class=o>!</span><span class=p>(</span><span class=n>lhs</span><span class=w> </span><span class=o>==</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span></code>.</p> <ul> <li>This means the comparison is simply the logical negation of <code>operator==</code>, including for special values like <code>NaN</code> and <code>discarded</code>.</li> </ul> </li> <li> <p>Compares a <abbr title="JavaScript Object Notation">JSON</abbr> value and a scalar or a scalar and a <abbr title="JavaScript Object Notation">JSON</abbr> value for inequality by converting the scalar to a <abbr title="JavaScript Object Notation">JSON</abbr> value and comparing both <abbr title="JavaScript Object Notation">JSON</abbr> values according to 1.</p> </li> </ol> <h2 id=template-parameters>Template parameters<a class=headerlink href=#template-parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>ScalarType</code></dt> <dd>a scalar type according to <code>std::is_scalar&lt;ScalarType&gt;::value</code></dd> </dl> <h2 id=parameters>Parameters<a class=headerlink href=#parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>lhs</code> (in)</dt> <dd>first value to consider </dd> <dt><code>rhs</code> (in)</dt> <dd>second value to consider </dd> </dl> <h2 id=return-value>Return value<a class=headerlink href=#return-value title="Permanent link">&para;</a></h2> <p>whether the values <code>lhs</code>/<code>*this</code> and <code>rhs</code> are not equal</p> <h2 id=exception-safety>Exception safety<a class=headerlink href=#exception-safety title="Permanent link">&para;</a></h2> <p>No-throw guarantee: this function never throws exceptions.</p> <h2 id=complexity>Complexity<a class=headerlink href=#complexity title="Permanent link">&para;</a></h2> <p>Linear.</p> <h2 id=notes>Notes<a class=headerlink href=#notes title="Permanent link">&para;</a></h2> <div class="admonition note"> <p class=admonition-title>C++20</p> <p>Since C++20, <code>basic_json</code> declares no <code>operator!=</code>. The compiler rewrites <code class=highlight><span class=n>a</span><span class=w> </span><span class=o>!=</span><span class=w> </span><span class=n>b</span></code> as <code class=highlight><span class=o>!</span><span class=p>(</span><span class=n>a</span><span class=w> </span><span class=o>==</span><span class=w> </span><span class=n>b</span><span class=p>)</span></code> using <a href=../operator_eq/ ><code>operator==</code></a>, so the result is the same as described above.</p> </div> <div class="admonition note"> <p class=admonition-title>Comparing <code>NaN</code> and <code>discarded</code></p> <p>Since <code>operator!=</code> is defined as <code>!(a == b)</code>, the behavior for special values follows that of <code>operator==</code>:</p> <ul> <li>For <code>NaN</code> values: <code>NaN == NaN</code> yields <code class=highlight><span class=nb>false</span></code>, so <code>NaN != NaN</code> yields <code class=highlight><span class=nb>true</span></code>.</li> <li>For <code>discarded</code> values: <code>discarded == x</code> yields <code class=highlight><span class=nb>false</span></code> for any <code>x</code>, so <code>discarded != x</code> yields <code class=highlight><span class=nb>true</span></code>.</li> </ul> </div> <h2 id=examples>Examples<a class=headerlink href=#examples title="Permanent link">&para;</a></h2> <details class=example> <summary>Example: (1) compare <abbr title="JavaScript Object Notation">JSON</abbr> values</summary> <p>The example demonstrates comparing several <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class=highlight><pre><span></span><code><span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;iostream&gt;</span> </code></pre></div> <ol> <li> <p>Compares two <abbr title="JavaScript Object Notation">JSON</abbr> values for inequality. Returns <code class=highlight><span class=o>!</span><span class=p>(</span><span class=n>lhs</span><span class=w> </span><span class=o>==</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span></code>.</p> <ul> <li>This means the comparison is simply the logical negation of <code>operator==</code>, including for special values like <code>NaN</code> and <code>discarded</code>.</li> </ul> </li> <li> <p>Compares a <abbr title="JavaScript Object Notation">JSON</abbr> value and a scalar or a scalar and a <abbr title="JavaScript Object Notation">JSON</abbr> value for inequality by converting the scalar to a <abbr title="JavaScript Object Notation">JSON</abbr> value and comparing both <abbr title="JavaScript Object Notation">JSON</abbr> values according to 1.</p> </li> </ol> <h2 id=template-parameters>Template parameters<a class=headerlink href=#template-parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>ScalarType</code></dt> <dd>a scalar type according to <code>std::is_scalar&lt;ScalarType&gt;::value</code></dd> </dl> <h2 id=parameters>Parameters<a class=headerlink href=#parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>lhs</code> (in)</dt> <dd>first value to consider </dd> <dt><code>rhs</code> (in)</dt> <dd>second value to consider </dd> </dl> <h2 id=return-value>Return value<a class=headerlink href=#return-value title="Permanent link">&para;</a></h2> <p>whether the values <code>lhs</code>/<code>*this</code> and <code>rhs</code> are not equal</p> <h2 id=exception-safety>Exception safety<a class=headerlink href=#exception-safety title="Permanent link">&para;</a></h2> <ol> <li>No-throw guarantee: this function never throws exceptions.</li> <li>No-throw guarantee if converting the scalar to a <abbr title="JavaScript Object Notation">JSON</abbr> value cannot throw, as for numbers, Booleans, and <code class=highlight><span class=nb>nullptr</span></code>; the function is <code class=highlight><span class=k>noexcept</span></code> exactly in that case. Otherwise, it throws what the conversion throws, for example <code>std::bad_alloc</code> when converting a string, or <a href=../../../home/exceptions/#jsonexceptionout_of_range410><code>out_of_range.410</code></a> for an enum value not mapped by <a href=../../macros/nlohmann_json_serialize_enum_strict/ ><code>NLOHMANN_JSON_SERIALIZE_ENUM_STRICT</code></a>.</li> </ol> <h2 id=complexity>Complexity<a class=headerlink href=#complexity title="Permanent link">&para;</a></h2> <p>Linear.</p> <h2 id=notes>Notes<a class=headerlink href=#notes title="Permanent link">&para;</a></h2> <div class="admonition note"> <p class=admonition-title>C++20</p> <p>Since C++20, <code>basic_json</code> declares no <code>operator!=</code>. The compiler rewrites <code class=highlight><span class=n>a</span><span class=w> </span><span class=o>!=</span><span class=w> </span><span class=n>b</span></code> as <code class=highlight><span class=o>!</span><span class=p>(</span><span class=n>a</span><span class=w> </span><span class=o>==</span><span class=w> </span><span class=n>b</span><span class=p>)</span></code> using <a href=../operator_eq/ ><code>operator==</code></a>, so the result is the same as described above.</p> </div> <div class="admonition note"> <p class=admonition-title>Comparing <code>NaN</code> and <code>discarded</code></p> <p>Since <code>operator!=</code> is defined as <code>!(a == b)</code>, the behavior for special values follows that of <code>operator==</code>:</p> <ul> <li>For <code>NaN</code> values: <code>NaN == NaN</code> yields <code class=highlight><span class=nb>false</span></code>, so <code>NaN != NaN</code> yields <code class=highlight><span class=nb>true</span></code>.</li> <li>For <code>discarded</code> values: <code>discarded == x</code> yields <code class=highlight><span class=nb>false</span></code> for any <code>x</code>, so <code>discarded != x</code> yields <code class=highlight><span class=nb>true</span></code>.</li> </ul> </div> <h2 id=examples>Examples<a class=headerlink href=#examples title="Permanent link">&para;</a></h2> <details class=example> <summary>Example: (1) compare <abbr title="JavaScript Object Notation">JSON</abbr> values</summary> <p>The example demonstrates comparing several <abbr title="JavaScript Object Notation">JSON</abbr> types.</p> <div class=highlight><pre><span></span><code><span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;iostream&gt;</span>
<span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;nlohmann/json.hpp&gt;</span> <span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;nlohmann/json.hpp&gt;</span>
<span class=k>using</span><span class=w> </span><span class=n>json</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=n>nlohmann</span><span class=o>::</span><span class=n>json</span><span class=p>;</span> <span class=k>using</span><span class=w> </span><span class=n>json</span><span class=w> </span><span class=o>=</span><span class=w> </span><span class=n>nlohmann</span><span class=o>::</span><span class=n>json</span><span class=p>;</span>
@@ -61,4 +61,4 @@
<span class=mi>17</span><span class=w> </span><span class=err>!=</span><span class=w> </span><span class=kc>null</span><span class=err>p</span><span class=kc>tr</span><span class=w> </span><span class=kc>true</span> <span class=mi>17</span><span class=w> </span><span class=err>!=</span><span class=w> </span><span class=kc>null</span><span class=err>p</span><span class=kc>tr</span><span class=w> </span><span class=kc>true</span>
<span class=s2>"foo"</span><span class=w> </span><span class=err>!=</span><span class=w> </span><span class=kc>null</span><span class=err>p</span><span class=kc>tr</span><span class=w> </span><span class=kc>true</span> <span class=s2>"foo"</span><span class=w> </span><span class=err>!=</span><span class=w> </span><span class=kc>null</span><span class=err>p</span><span class=kc>tr</span><span class=w> </span><span class=kc>true</span>
<span class=kc>null</span><span class=w> </span><span class=err>!=</span><span class=w> </span><span class=kc>null</span><span class=err>p</span><span class=kc>tr</span><span class=w> </span><span class=kc>false</span> <span class=kc>null</span><span class=w> </span><span class=err>!=</span><span class=w> </span><span class=kc>null</span><span class=err>p</span><span class=kc>tr</span><span class=w> </span><span class=kc>false</span>
</code></pre></div> </details> <h2 id=see-also>See also<a class=headerlink href=#see-also title="Permanent link">&para;</a></h2> <ul> <li><a href=../operator_eq/ >operator==</a> comparison: equal</li> <li><a href=../operator_spaceship/ >operator&lt;=&gt;</a> comparison: 3-way (C++20)</li> </ul> <h2 id=version-history>Version history<a class=headerlink href=#version-history title="Permanent link">&para;</a></h2> <ol> <li>Added in version 1.0.0. Added a C++20 member function in version 3.11.0. Changed in version 3.13.0 <span class=unreleased-version title="Not part of a release yet; the latest release is 3.12.0.">unreleased</span> to remove special-casing for <code>NaN</code> and <code>discarded</code> values; <code>operator!=</code> now consistently means <code>!(a == b)</code>. Removed the C++20 member function in version 3.13.0 <span class=unreleased-version title="Not part of a release yet; the latest release is 3.12.0.">unreleased</span>; since C++20, the compiler rewrites <code>a != b</code> using <code>operator==</code>.</li> <li>Added in version 1.0.0. Changed in version 3.13.0 <span class=unreleased-version title="Not part of a release yet; the latest release is 3.12.0.">unreleased</span> to remove special-casing for <code>NaN</code> and <code>discarded</code> values; <code>operator!=</code> now consistently means <code>!(a == b)</code>. Since C++20, the compiler rewrites <code>a != b</code> using <code>operator==</code>.</li> </ol> <!-- https://squidfunk.github.io/mkdocs-material/reference/tooltips/#adding-a-glossary --> <aside class=md-source-file> <span class=md-source-file__fact> <span class=md-icon title="Last update"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1zM12.5 7v5.2l4 2.4-1 1L11 13V7zM11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2z"/></svg> </span> <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date" title="October 2, 2026 09:32:15 UTC">October 2, 2026</span> </span> </aside> </article> </div> <script>var tabs=__md_get("__tabs");if(Array.isArray(tabs))e:for(var set of document.querySelectorAll(".tabbed-set")){var labels=set.querySelector(".tabbed-labels");for(var tab of tabs)for(var label of labels.getElementsByTagName("label"))if(label.innerText.trim()===tab){var input=document.getElementById(label.htmlFor);input.checked=!0;continue e}}</script> <script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script> </div> <button type=button class="md-top md-icon" data-md-component=top hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z"/></svg> Back to top </button> </main> <footer class=md-footer> <div class="md-footer-meta md-typeset"> <div class="md-footer-meta__inner md-grid"> <div class=md-copyright> <div class=md-copyright__highlight> Copyright &copy; 2013-2026 Niels Lohmann </div> </div> <div class=md-social> <a href="https://github.com/nlohmann" target="_blank" rel="noopener" title="github.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 512 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M173.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6m-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3m44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9M252.8 8C114.1 8 8 113.3 8 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C436.2 457.8 504 362.9 504 252 504 113.3 391.5 8 252.8 8M105.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1m-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7m32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1m-11.4-14.7c-1.6 1-1.6 3.6 0 5.9s4.3 3.3 5.6 2.3c1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2"/></svg> </a> <a href="https://www.linkedin.com/in/nielslohmann/" target="_Line truncated </code></pre></div> </details> <h2 id=see-also>See also<a class=headerlink href=#see-also title="Permanent link">&para;</a></h2> <ul> <li><a href=../operator_eq/ >operator==</a> comparison: equal</li> <li><a href=../operator_spaceship/ >operator&lt;=&gt;</a> comparison: 3-way (C++20)</li> </ul> <h2 id=version-history>Version history<a class=headerlink href=#version-history title="Permanent link">&para;</a></h2> <ol> <li>Added in version 1.0.0. Added a C++20 member function in version 3.11.0. Changed in version 3.13.0 <span class=unreleased-version title="Not part of a release yet; the latest release is 3.12.0.">unreleased</span> to remove special-casing for <code>NaN</code> and <code>discarded</code> values; <code>operator!=</code> now consistently means <code>!(a == b)</code>. Removed the C++20 member function in version 3.13.0 <span class=unreleased-version title="Not part of a release yet; the latest release is 3.12.0.">unreleased</span>; since C++20, the compiler rewrites <code>a != b</code> using <code>operator==</code>.</li> <li>Added in version 1.0.0. Changed in version 3.13.0 <span class=unreleased-version title="Not part of a release yet; the latest release is 3.12.0.">unreleased</span> to remove special-casing for <code>NaN</code> and <code>discarded</code> values; <code>operator!=</code> now consistently means <code>!(a == b)</code>. Since C++20, the compiler rewrites <code>a != b</code> using <code>operator==</code>. Made conditionally <code class=highlight><span class=k>noexcept</span></code> in version 3.13.0 <span class=unreleased-version title="Not part of a release yet; the latest release is 3.12.0.">unreleased</span>; before, a throwing conversion called <code>std::terminate</code>.</li> </ol> <!-- https://squidfunk.github.io/mkdocs-material/reference/tooltips/#adding-a-glossary --> <aside class=md-source-file> <span class=md-source-file__fact> <span class=md-icon title="Last update"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1zM12.5 7v5.2l4 2.4-1 1L11 13V7zM11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2z"/></svg> </span> <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date" title="October 2, 2026 15:25:17 UTC">October 2, 2026</span> </span> </aside> </article> </div> <script>var tabs=__md_get("__tabs");if(Array.isArray(tabs))e:for(var set of document.querySelectorAll(".tabbed-set")){var labels=set.querySelector(".tabbed-labels");for(var tab of tabs)for(var label of labels.getElementsByTagName("label"))if(label.innerText.trim()===tab){var input=document.getElementById(label.htmlFor);input.checked=!0;continue e}}</script> <script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script> </div> <button type=button class="md-top md-icon" data-md-component=top hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z"/></svg> Back to top </button> </main> <footer class=md-footer> <div class="md-footer-meta md-typeset"> <div class="md-footer-meta__inner md-grid"> <div class=md-copyright> <div class=md-copyright__highlight> Copyright &copy; 2013-2026 Niels Lohmann </div> </div> <div class=md-social> <a href="https://github.com/nlohmann" target="_blank" rel="noopener" title="github.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 512 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M173.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6m-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3m44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9M252.8 8C114.1 8 8 113.3 8 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C436.2 457.8 504 362.9 504 252 504 113.3 391.5 8 252.8 8M105.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1m-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-Line truncated
+5 -4
View File
@@ -5,10 +5,10 @@
bool operator!=(const_reference lhs, const_reference rhs) noexcept; // (1) bool operator!=(const_reference lhs, const_reference rhs) noexcept; // (1)
template<typename ScalarType> template<typename ScalarType>
bool operator!=(const_reference lhs, const ScalarType rhs) noexcept; // (2) bool operator!=(const_reference lhs, const ScalarType rhs) noexcept(/* see below */); // (2)
template<typename ScalarType> template<typename ScalarType>
bool operator!=(ScalarType lhs, const const_reference rhs) noexcept; // (2) bool operator!=(ScalarType lhs, const const_reference rhs) noexcept(/* see below */); // (2)
``` ```
1. Compares two JSON values for inequality. Returns `!(lhs == rhs)`. 1. Compares two JSON values for inequality. Returns `!(lhs == rhs)`.
@@ -33,7 +33,8 @@ whether the values `lhs`/`*this` and `rhs` are not equal
## Exception safety ## Exception safety
No-throw guarantee: this function never throws exceptions. 1. No-throw guarantee: this function never throws exceptions.
1. No-throw guarantee if converting the scalar to a JSON value cannot throw, as for numbers, Booleans, and `nullptr`; the function is `noexcept` exactly in that case. Otherwise, it throws what the conversion throws, for example `std::bad_alloc` when converting a string, or [`out_of_range.410`](https://json.nlohmann.me/home/exceptions/#jsonexceptionout_of_range410) for an enum value not mapped by [`NLOHMANN_JSON_SERIALIZE_ENUM_STRICT`](https://json.nlohmann.me/api/macros/nlohmann_json_serialize_enum_strict/index.md).
## Complexity ## Complexity
@@ -141,4 +142,4 @@ null != nullptr false
## Version history ## Version history
1. Added in version 1.0.0. Added a C++20 member function in version 3.11.0. Changed in version 3.13.0 unreleased to remove special-casing for `NaN` and `discarded` values; `operator!=` now consistently means `!(a == b)`. Removed the C++20 member function in version 3.13.0 unreleased; since C++20, the compiler rewrites `a != b` using `operator==`. 1. Added in version 1.0.0. Added a C++20 member function in version 3.11.0. Changed in version 3.13.0 unreleased to remove special-casing for `NaN` and `discarded` values; `operator!=` now consistently means `!(a == b)`. Removed the C++20 member function in version 3.13.0 unreleased; since C++20, the compiler rewrites `a != b` using `operator==`.
1. Added in version 1.0.0. Changed in version 3.13.0 unreleased to remove special-casing for `NaN` and `discarded` values; `operator!=` now consistently means `!(a == b)`. Since C++20, the compiler rewrites `a != b` using `operator==`. 1. Added in version 1.0.0. Changed in version 3.13.0 unreleased to remove special-casing for `NaN` and `discarded` values; `operator!=` now consistently means `!(a == b)`. Since C++20, the compiler rewrites `a != b` using `operator==`. Made conditionally `noexcept` in version 3.13.0 unreleased; before, a throwing conversion called `std::terminate`.
+8 -2
View File
@@ -6,7 +6,7 @@ class basic_json {
std::partial_ordering operator<=>(const_reference rhs) const noexcept; // (1) std::partial_ordering operator<=>(const_reference rhs) const noexcept; // (1)
template<typename ScalarType> template<typename ScalarType>
std::partial_ordering operator<=>(const ScalarType rhs) const noexcept; // (2) std::partial_ordering operator<=>(const ScalarType rhs) const noexcept(/* see below */); // (2)
}; };
``` ```
@@ -39,7 +39,12 @@ the `std::partial_ordering` of the 3-way comparison of `*this` and `rhs`
## Exception safety ## Exception safety
No-throw guarantee: this function never throws exceptions. 1. No-throw guarantee: this function never throws exceptions.
2. No-throw guarantee if converting the scalar to a JSON value cannot throw, as for numbers, Booleans, and
`#!cpp nullptr`; the function is `#!cpp noexcept` exactly in that case. Otherwise, it throws what the conversion
throws, for example `std::bad_alloc` when converting a string, or
[`out_of_range.410`](../../home/exceptions.md#jsonexceptionout_of_range410) for an enum value not mapped by
[`NLOHMANN_JSON_SERIALIZE_ENUM_STRICT`](../macros/nlohmann_json_serialize_enum_strict.md).
## Complexity ## Complexity
@@ -98,3 +103,4 @@ Linear.
1. Added in version 3.11.0. 1. Added in version 3.11.0.
2. Added in version 3.11.0. 2. Added in version 3.11.0.
Made conditionally `#!cpp noexcept` in version 3.13.0; before, a throwing conversion called `std::terminate`.
+3 -3
View File
@@ -3,9 +3,9 @@
<span class=w> </span><span class=n>std</span><span class=o>::</span><span class=n>partial_ordering</span><span class=w> </span><span class=k>operator</span><span class=o>&lt;=&gt;</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (1)</span> <span class=w> </span><span class=n>std</span><span class=o>::</span><span class=n>partial_ordering</span><span class=w> </span><span class=k>operator</span><span class=o>&lt;=&gt;</span><span class=p>(</span><span class=n>const_reference</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (1)</span>
<span class=w> </span><span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span> <span class=w> </span><span class=k>template</span><span class=o>&lt;</span><span class=k>typename</span><span class=w> </span><span class=nc>ScalarType</span><span class=o>&gt;</span>
<span class=w> </span><span class=n>std</span><span class=o>::</span><span class=n>partial_ordering</span><span class=w> </span><span class=k>operator</span><span class=o>&lt;=&gt;</span><span class=p>(</span><span class=k>const</span><span class=w> </span><span class=n>ScalarType</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=k>noexcept</span><span class=p>;</span><span class=w> </span><span class=c1>// (2)</span> <span class=w> </span><span class=n>std</span><span class=o>::</span><span class=n>partial_ordering</span><span class=w> </span><span class=k>operator</span><span class=o>&lt;=&gt;</span><span class=p>(</span><span class=k>const</span><span class=w> </span><span class=n>ScalarType</span><span class=w> </span><span class=n>rhs</span><span class=p>)</span><span class=w> </span><span class=k>const</span><span class=w> </span><span class=k>noexcept</span><span class=p>(</span><span class=cm>/* see below */</span><span class=p>);</span><span class=w> </span><span class=c1>// (2)</span>
<span class=p>};</span> <span class=p>};</span>
</code></pre></div> <ol> <li> <p>3-way compares two <abbr title="JavaScript Object Notation">JSON</abbr> values producing a result of type <code>std::partial_ordering</code> according to the following rules:</p> <ul> <li>Two <abbr title="JavaScript Object Notation">JSON</abbr> values compare with a result of <code>std::partial_ordering::unordered</code> if either value is discarded.</li> <li>If both <abbr title="JavaScript Object Notation">JSON</abbr> values are of the same type, the result is produced by 3-way comparing their stored values using their respective <code>operator&lt;=&gt;</code>.</li> <li>Integer and floating-point numbers are converted to their common type and then 3-way compared using their respective <code>operator&lt;=&gt;</code>. For instance, comparing an integer and a floating-point value will 3-way compare the first value converted to floating-point with the second value.</li> <li>Otherwise, yields a result by comparing the type (see <a href=../value_t/ ><code>value_t</code></a>).</li> </ul> </li> <li> <p>3-way compares a <abbr title="JavaScript Object Notation">JSON</abbr> value and a scalar or a scalar and a <abbr title="JavaScript Object Notation">JSON</abbr> value by converting the scalar to a <abbr title="JavaScript Object Notation">JSON</abbr> value and 3-way comparing both <abbr title="JavaScript Object Notation">JSON</abbr> values (see 1).</p> </li> </ol> <h2 id=template-parameters>Template parameters<a class=headerlink href=#template-parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>ScalarType</code></dt> <dd>a scalar type according to <code>std::is_scalar&lt;ScalarType&gt;::value</code></dd> </dl> <h2 id=parameters>Parameters<a class=headerlink href=#parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>rhs</code> (in)</dt> <dd>second value to consider </dd> </dl> <h2 id=return-value>Return value<a class=headerlink href=#return-value title="Permanent link">&para;</a></h2> <p>the <code>std::partial_ordering</code> of the 3-way comparison of <code>*this</code> and <code>rhs</code></p> <h2 id=exception-safety>Exception safety<a class=headerlink href=#exception-safety title="Permanent link">&para;</a></h2> <p>No-throw guarantee: this function never throws exceptions.</p> <h2 id=complexity>Complexity<a class=headerlink href=#complexity title="Permanent link">&para;</a></h2> <p>Linear.</p> <h2 id=notes>Notes<a class=headerlink href=#notes title="Permanent link">&para;</a></h2> <div class="admonition note"> <p class=admonition-title>Comparing <code>NaN</code></p> <ul> <li><code>NaN</code> values are unordered within the domain of numbers. The following comparisons all yield <code>std::partial_ordering::unordered</code>:<ol> <li>Comparing a <code>NaN</code> with itself.</li> <li>Comparing a <code>NaN</code> with another <code>NaN</code>.</li> <li>Comparing a <code>NaN</code> and any other number.</li> </ol> </li> </ul> </div> <h2 id=examples>Examples<a class=headerlink href=#examples title="Permanent link">&para;</a></h2> <details class=example> <summary>Example: (1) comparing <abbr title="JavaScript Object Notation">JSON</abbr> values</summary> <p>The example demonstrates comparing several <abbr title="JavaScript Object Notation">JSON</abbr> values.</p> <div class=highlight><pre><span></span><code><span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;compare&gt;</span> </code></pre></div> <ol> <li> <p>3-way compares two <abbr title="JavaScript Object Notation">JSON</abbr> values producing a result of type <code>std::partial_ordering</code> according to the following rules:</p> <ul> <li>Two <abbr title="JavaScript Object Notation">JSON</abbr> values compare with a result of <code>std::partial_ordering::unordered</code> if either value is discarded.</li> <li>If both <abbr title="JavaScript Object Notation">JSON</abbr> values are of the same type, the result is produced by 3-way comparing their stored values using their respective <code>operator&lt;=&gt;</code>.</li> <li>Integer and floating-point numbers are converted to their common type and then 3-way compared using their respective <code>operator&lt;=&gt;</code>. For instance, comparing an integer and a floating-point value will 3-way compare the first value converted to floating-point with the second value.</li> <li>Otherwise, yields a result by comparing the type (see <a href=../value_t/ ><code>value_t</code></a>).</li> </ul> </li> <li> <p>3-way compares a <abbr title="JavaScript Object Notation">JSON</abbr> value and a scalar or a scalar and a <abbr title="JavaScript Object Notation">JSON</abbr> value by converting the scalar to a <abbr title="JavaScript Object Notation">JSON</abbr> value and 3-way comparing both <abbr title="JavaScript Object Notation">JSON</abbr> values (see 1).</p> </li> </ol> <h2 id=template-parameters>Template parameters<a class=headerlink href=#template-parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>ScalarType</code></dt> <dd>a scalar type according to <code>std::is_scalar&lt;ScalarType&gt;::value</code></dd> </dl> <h2 id=parameters>Parameters<a class=headerlink href=#parameters title="Permanent link">&para;</a></h2> <dl> <dt><code>rhs</code> (in)</dt> <dd>second value to consider </dd> </dl> <h2 id=return-value>Return value<a class=headerlink href=#return-value title="Permanent link">&para;</a></h2> <p>the <code>std::partial_ordering</code> of the 3-way comparison of <code>*this</code> and <code>rhs</code></p> <h2 id=exception-safety>Exception safety<a class=headerlink href=#exception-safety title="Permanent link">&para;</a></h2> <ol> <li>No-throw guarantee: this function never throws exceptions.</li> <li>No-throw guarantee if converting the scalar to a <abbr title="JavaScript Object Notation">JSON</abbr> value cannot throw, as for numbers, Booleans, and <code class=highlight><span class=nb>nullptr</span></code>; the function is <code class=highlight><span class=k>noexcept</span></code> exactly in that case. Otherwise, it throws what the conversion throws, for example <code>std::bad_alloc</code> when converting a string, or <a href=../../../home/exceptions/#jsonexceptionout_of_range410><code>out_of_range.410</code></a> for an enum value not mapped by <a href=../../macros/nlohmann_json_serialize_enum_strict/ ><code>NLOHMANN_JSON_SERIALIZE_ENUM_STRICT</code></a>.</li> </ol> <h2 id=complexity>Complexity<a class=headerlink href=#complexity title="Permanent link">&para;</a></h2> <p>Linear.</p> <h2 id=notes>Notes<a class=headerlink href=#notes title="Permanent link">&para;</a></h2> <div class="admonition note"> <p class=admonition-title>Comparing <code>NaN</code></p> <ul> <li><code>NaN</code> values are unordered within the domain of numbers. The following comparisons all yield <code>std::partial_ordering::unordered</code>:<ol> <li>Comparing a <code>NaN</code> with itself.</li> <li>Comparing a <code>NaN</code> with another <code>NaN</code>.</li> <li>Comparing a <code>NaN</code> and any other number.</li> </ol> </li> </ul> </div> <h2 id=examples>Examples<a class=headerlink href=#examples title="Permanent link">&para;</a></h2> <details class=example> <summary>Example: (1) comparing <abbr title="JavaScript Object Notation">JSON</abbr> values</summary> <p>The example demonstrates comparing several <abbr title="JavaScript Object Notation">JSON</abbr> values.</p> <div class=highlight><pre><span></span><code><span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;compare&gt;</span>
<span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;iostream&gt;</span> <span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;iostream&gt;</span>
<span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;nlohmann/json.hpp&gt;</span> <span class=cp>#include</span><span class=w> </span><span class=cpf>&lt;nlohmann/json.hpp&gt;</span>
@@ -93,4 +93,4 @@
<span class=mi>17</span><span class=w> </span><span class=err>&lt;=&gt;</span><span class=w> </span><span class=mf>17.000000</span><span class=w> </span><span class=p>:</span><span class=err>=</span><span class=w> </span><span class=err>equivale</span><span class=kc>nt</span> <span class=mi>17</span><span class=w> </span><span class=err>&lt;=&gt;</span><span class=w> </span><span class=mf>17.000000</span><span class=w> </span><span class=p>:</span><span class=err>=</span><span class=w> </span><span class=err>equivale</span><span class=kc>nt</span>
<span class=mi>17</span><span class=w> </span><span class=err>&lt;=&gt;</span><span class=w> </span><span class=kc>nan</span><span class=w> </span><span class=p>:</span><span class=err>=</span><span class=w> </span><span class=err>u</span><span class=kc>n</span><span class=err>ordered</span> <span class=mi>17</span><span class=w> </span><span class=err>&lt;=&gt;</span><span class=w> </span><span class=kc>nan</span><span class=w> </span><span class=p>:</span><span class=err>=</span><span class=w> </span><span class=err>u</span><span class=kc>n</span><span class=err>ordered</span>
<span class=s2>"17"</span><span class=w> </span><span class=err>&lt;=&gt;</span><span class=w> </span><span class=mi>17</span><span class=w> </span><span class=p>:</span><span class=err>=</span><span class=w> </span><span class=err>grea</span><span class=kc>ter</span> <span class=s2>"17"</span><span class=w> </span><span class=err>&lt;=&gt;</span><span class=w> </span><span class=mi>17</span><span class=w> </span><span class=p>:</span><span class=err>=</span><span class=w> </span><span class=err>grea</span><span class=kc>ter</span>
</code></pre></div> </details> <h2 id=see-also>See also<a class=headerlink href=#see-also title="Permanent link">&para;</a></h2> <ul> <li><a href=../operator_eq/ ><strong>operator==</strong></a> - comparison: equal</li> <li><a href=../operator_ne/ ><strong>operator!=</strong></a> - comparison: not equal</li> <li><a href=../operator_lt/ ><strong>operator&lt;</strong></a> - comparison: less than</li> <li><a href=../operator_le/ ><strong>operator&lt;=</strong></a> - comparison: less than or equal</li> <li><a href=../operator_gt/ ><strong>operator&gt;</strong></a> - comparison: greater than</li> <li><a href=../operator_ge/ ><strong>operator&gt;=</strong></a> - comparison: greater than or equal</li> </ul> <h2 id=version-history>Version history<a class=headerlink href=#version-history title="Permanent link">&para;</a></h2> <ol> <li>Added in version 3.11.0.</li> <li>Added in version 3.11.0.</li> </ol> <!-- https://squidfunk.github.io/mkdocs-material/reference/tooltips/#adding-a-glossary --> <aside class=md-source-file> <span class=md-source-file__fact> <span class=md-icon title="Last update"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1zM12.5 7v5.2l4 2.4-1 1L11 13V7zM11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2z"/></svg> </span> <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date" title="August 5, 2022 17:51:39 UTC">August 5, 2022</span> </span> </aside> </article> </div> <script>var tabs=__md_get("__tabs");if(Array.isArray(tabs))e:for(var set of document.querySelectorAll(".tabbed-set")){var labels=set.querySelector(".tabbed-labels");for(var tab of tabs)for(var label of labels.getElementsByTagName("label"))if(label.innerText.trim()===tab){var input=document.getElementById(label.htmlFor);input.checked=!0;continue e}}</script> <script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script> </div> <button type=button class="md-top md-icon" data-md-component=top hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z"/></svg> Back to top </button> </main> <footer class=md-footer> <div class="md-footer-meta md-typeset"> <div class="md-footer-meta__inner md-grid"> <div class=md-copyright> <div class=md-copyright__highlight> Copyright &copy; 2013-2026 Niels Lohmann </div> </div> <div class=md-social> <a href="https://github.com/nlohmann" target="_blank" rel="noopener" title="github.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 512 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M173.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6m-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3m44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9M252.8 8C114.1 8 8 113.3 8 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C436.2 457.8 504 362.9 504 252 504 113.3 391.5 8 252.8 8M105.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1m-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7m32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1m-11.4-14.7c-1.6 1-1.6 3.6 0 5.9s4.3 3.3 5.6 2.3c1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2"/></svg> </a> <a href="https://www.linkedin.com/in/nielslohmann/" target="_blank" rel="noopener" title="www.linkedin.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 448 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M416 32H31.9C14.3 32 0 46.5 0 64.3v383.4C0 465.5 14.3 480 31.9 480H416c17.6 0 32-14.5 32-32.3V64.3c0-17.8-14.4-32.3-32-32.3M135.4 416H69V202.2h66.5V416zM102.2 96a38.5 38.5 0 1 1 0 77 38.5 38.5 0 1 1 0-77m282.Line truncated </code></pre></div> </details> <h2 id=see-also>See also<a class=headerlink href=#see-also title="Permanent link">&para;</a></h2> <ul> <li><a href=../operator_eq/ ><strong>operator==</strong></a> - comparison: equal</li> <li><a href=../operator_ne/ ><strong>operator!=</strong></a> - comparison: not equal</li> <li><a href=../operator_lt/ ><strong>operator&lt;</strong></a> - comparison: less than</li> <li><a href=../operator_le/ ><strong>operator&lt;=</strong></a> - comparison: less than or equal</li> <li><a href=../operator_gt/ ><strong>operator&gt;</strong></a> - comparison: greater than</li> <li><a href=../operator_ge/ ><strong>operator&gt;=</strong></a> - comparison: greater than or equal</li> </ul> <h2 id=version-history>Version history<a class=headerlink href=#version-history title="Permanent link">&para;</a></h2> <ol> <li>Added in version 3.11.0.</li> <li>Added in version 3.11.0. Made conditionally <code class=highlight><span class=k>noexcept</span></code> in version 3.13.0 <span class=unreleased-version title="Not part of a release yet; the latest release is 3.12.0.">unreleased</span>; before, a throwing conversion called <code>std::terminate</code>.</li> </ol> <!-- https://squidfunk.github.io/mkdocs-material/reference/tooltips/#adding-a-glossary --> <aside class=md-source-file> <span class=md-source-file__fact> <span class=md-icon title="Last update"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1zM12.5 7v5.2l4 2.4-1 1L11 13V7zM11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2z"/></svg> </span> <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date" title="October 2, 2026 15:25:17 UTC">October 2, 2026</span> </span> </aside> </article> </div> <script>var tabs=__md_get("__tabs");if(Array.isArray(tabs))e:for(var set of document.querySelectorAll(".tabbed-set")){var labels=set.querySelector(".tabbed-labels");for(var tab of tabs)for(var label of labels.getElementsByTagName("label"))if(label.innerText.trim()===tab){var input=document.getElementById(label.htmlFor);input.checked=!0;continue e}}</script> <script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script> </div> <button type=button class="md-top md-icon" data-md-component=top hidden> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z"/></svg> Back to top </button> </main> <footer class=md-footer> <div class="md-footer-meta md-typeset"> <div class="md-footer-meta__inner md-grid"> <div class=md-copyright> <div class=md-copyright__highlight> Copyright &copy; 2013-2026 Niels Lohmann </div> </div> <div class=md-social> <a href="https://github.com/nlohmann" target="_blank" rel="noopener" title="github.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 512 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M173.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6m-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3m44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9M252.8 8C114.1 8 8 113.3 8 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C436.2 457.8 504 362.9 504 252 504 113.3 391.5 8 252.8 8M105.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1m-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7m32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1m-11.4-14.7c-1.6 1-1.6 3.6 0 5.9s4.3 3.3 5.6 2.3c1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2"/></svg> </a> <a href="https://www.linkedin.com/in/nielslohmann/" target="_blank" rel="noopener" title="www.linkedin.com" class="md-social__link"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 448 512"><!-- Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SILLine truncated
+4 -3
View File
@@ -6,7 +6,7 @@ class basic_json {
std::partial_ordering operator<=>(const_reference rhs) const noexcept; // (1) std::partial_ordering operator<=>(const_reference rhs) const noexcept; // (1)
template<typename ScalarType> template<typename ScalarType>
std::partial_ordering operator<=>(const ScalarType rhs) const noexcept; // (2) std::partial_ordering operator<=>(const ScalarType rhs) const noexcept(/* see below */); // (2)
}; };
``` ```
@@ -33,7 +33,8 @@ the `std::partial_ordering` of the 3-way comparison of `*this` and `rhs`
## Exception safety ## Exception safety
No-throw guarantee: this function never throws exceptions. 1. No-throw guarantee: this function never throws exceptions.
1. No-throw guarantee if converting the scalar to a JSON value cannot throw, as for numbers, Booleans, and `nullptr`; the function is `noexcept` exactly in that case. Otherwise, it throws what the conversion throws, for example `std::bad_alloc` when converting a string, or [`out_of_range.410`](https://json.nlohmann.me/home/exceptions/#jsonexceptionout_of_range410) for an enum value not mapped by [`NLOHMANN_JSON_SERIALIZE_ENUM_STRICT`](https://json.nlohmann.me/api/macros/nlohmann_json_serialize_enum_strict/index.md).
## Complexity ## Complexity
@@ -174,4 +175,4 @@ false <=> true := less
## Version history ## Version history
1. Added in version 3.11.0. 1. Added in version 3.11.0.
1. Added in version 3.11.0. 1. Added in version 3.11.0. Made conditionally `noexcept` in version 3.13.0 unreleased; before, a throwing conversion called `std::terminate`.
+1 -1
View File
@@ -1 +1 @@
{"config":{"lang":["en"],"separator":"[\\s\\-\\.]","pipeline":["stopWordFilter"],"fields":{"title":{"boost":1000.0},"text":{"boost":1.0},"tags":{"boost":1000000.0}}},"docs":[{"location":"","title":"JSON for Modern C++","text":"<p>JSON for Modern C++ is a header-only C++11 library that turns JSON into a first-class C++ data type, using the operator magic of modern C++ so that creating, reading, and modifying JSON values feels as natural as it does in languages like Python. The whole library is available as a single header, <code>json.hpp</code>, with no dependencies, no subproject, and no complex build system to set up; a companion header, <code>json_fwd.hpp</code>, provides forward declarations to keep compile times down. See header-only integration for details. It is heavily unit-tested with 100% code coverage, checked with Valgrind and the Clang Sanitizers for memory leaks, and continuously fuzz-tested by Google OSS-Fuzz.</p>"},{"location":"#quick-start","title":"Quick start","text":"<p>Add the single header to your project and use the library like this:</p> <pre><code>#include &lt;iostream&gt;\n#include &lt;nlohmann/json.hpp&gt;\n\nusing json = nlohmann::json;\n\nint main()\n{\n // parse a JSON string\n json j = json::parse(R\"({\"happy\": true, \"pi\": 3.141})\");\n\n // access and modify values\n j[\"name\"] = \"Niels\";\n j[\"list\"] = {1, 0, 2};\n\n // serialize with an indent of 4 spaces\n std::cout &lt;&lt; j.dump(4) &lt;&lt; '\\n';\n}\n</code></pre> <p>Get the library by copying the single header <code>json.hpp</code> from the releases page into a directory <code>nlohmann</code> on your include path, or by installing it with a package manager:</p> <pre><code>brew install nlohmann-json # Homebrew\nvcpkg install nlohmann-json # vcpkg\n</code></pre> <pre><code>find_package(nlohmann_json 3.12.0 REQUIRED)\ntarget_link_libraries(myproject PRIVATE nlohmann_json::nlohmann_json)\n</code></pre> <p>See Integration for CMake in detail, all supported package managers (Conan, Meson, Bazel, Conda, and more), and pkg-config.</p>"},{"location":"#explore-the-documentation","title":"Explore the documentation","text":"<ul> <li> <p> Features</p> <p>Creating, parsing, accessing, and serializing JSON values, JSON Pointer/Patch, binary formats, and more.</p> <p> Features</p> </li> <li> <p> Integration</p> <p>Add the library to your project via a single header, CMake, a package manager, or pkg-config.</p> <p> Integration</p> </li> <li> <p> API documentation</p> <p>The complete reference for <code>basic_json</code> and its member functions, types, and related classes.</p> <p> API documentation</p> </li> <li> <p> FAQ</p> <p>Answers to common questions and known surprises when using the library.</p> <p> FAQ</p> </li> <li> <p> Releases</p> <p>What changed in each release, with links to the relevant documentation.</p> <p> Releases</p> </li> <li> <p> Community</p> <p>The ecosystem, contribution guidelines, governance, and quality assurance around the project.</p> <p> Community</p> </li> </ul> <p>Unreleased changes</p> <p>This documentation is built from the <code>develop</code> branch and may describe changes that are not part of a release yet. Their version numbers are followed by an unreleased badge; see Releases for what shipped in each version.</p> <p>The library is licensed under the MIT License. The source code, issue tracker, and discussions are on GitHub.</p>"},{"location":"api/json/","title":"nlohmann::json","text":"<pre><code>using json = basic_json&lt;&gt;;\n</code></pre> <p>This type is the default specialization of the basic_json class which uses the standard template types.</p>"},{"location":"api/json/#examples","title":"Examples","text":"Example <p>The example below demonstrates how to use the type <code>nlohmann::json</code>.</p> <pre><code>#include &lt;iostream&gt;\n#include &lt;iomanip&gt;\n#include &lt;nlohmann/json.hpp&gt;\n\nusing json = nlohmann::json;\n\nint main()\n{\n // create a JSON object\n json j =\n {\n {\"pi\", 3.141},\n {\"happy\", true},\n {\"name\", \"Niels\"},\n {\"nothing\", nullptr},\n {\n \"answer\", {\n {\"everything\", 42}\n }\n },\n {\"list\", {1, 0, 2}},\n {\n \"object\", {\n {\"currency\", \"USD\"},\n {\"value\", 42.99}\n }\n }\n };\n\n // add new values\n j[\"new\"][\"key\"][\"value\"] = {\"another\", \"list\"};\n\n // count elements\n auto s = j.size();\n j[\"size\"] = s;\n\n // pretty print with indent of 4 spaces\n std::cout &lt;&lt; std::setw(4) &lt;&lt; j &lt;&lt; '\\n';\n}\n</code></pre> <p>Output:</p> <pre><code>{\n \"answer\": {\n \"everything\": 42\n },\n \"happy\": true,\n \"list\": [\n 1,\n 0,\n 2\n ],\n \"name\": \"Niels\",\n \"new\": {\n \"key\": {\n \"value\": [\n \"another\",\n Line truncated {"config":{"lang":["en"],"separator":"[\\s\\-\\.]","pipeline":["stopWordFilter"],"fields":{"title":{"boost":1000.0},"text":{"boost":1.0},"tags":{"boost":1000000.0}}},"docs":[{"location":"","title":"JSON for Modern C++","text":"<p>JSON for Modern C++ is a header-only C++11 library that turns JSON into a first-class C++ data type, using the operator magic of modern C++ so that creating, reading, and modifying JSON values feels as natural as it does in languages like Python. The whole library is available as a single header, <code>json.hpp</code>, with no dependencies, no subproject, and no complex build system to set up; a companion header, <code>json_fwd.hpp</code>, provides forward declarations to keep compile times down. See header-only integration for details. It is heavily unit-tested with 100% code coverage, checked with Valgrind and the Clang Sanitizers for memory leaks, and continuously fuzz-tested by Google OSS-Fuzz.</p>"},{"location":"#quick-start","title":"Quick start","text":"<p>Add the single header to your project and use the library like this:</p> <pre><code>#include &lt;iostream&gt;\n#include &lt;nlohmann/json.hpp&gt;\n\nusing json = nlohmann::json;\n\nint main()\n{\n // parse a JSON string\n json j = json::parse(R\"({\"happy\": true, \"pi\": 3.141})\");\n\n // access and modify values\n j[\"name\"] = \"Niels\";\n j[\"list\"] = {1, 0, 2};\n\n // serialize with an indent of 4 spaces\n std::cout &lt;&lt; j.dump(4) &lt;&lt; '\\n';\n}\n</code></pre> <p>Get the library by copying the single header <code>json.hpp</code> from the releases page into a directory <code>nlohmann</code> on your include path, or by installing it with a package manager:</p> <pre><code>brew install nlohmann-json # Homebrew\nvcpkg install nlohmann-json # vcpkg\n</code></pre> <pre><code>find_package(nlohmann_json 3.12.0 REQUIRED)\ntarget_link_libraries(myproject PRIVATE nlohmann_json::nlohmann_json)\n</code></pre> <p>See Integration for CMake in detail, all supported package managers (Conan, Meson, Bazel, Conda, and more), and pkg-config.</p>"},{"location":"#explore-the-documentation","title":"Explore the documentation","text":"<ul> <li> <p> Features</p> <p>Creating, parsing, accessing, and serializing JSON values, JSON Pointer/Patch, binary formats, and more.</p> <p> Features</p> </li> <li> <p> Integration</p> <p>Add the library to your project via a single header, CMake, a package manager, or pkg-config.</p> <p> Integration</p> </li> <li> <p> API documentation</p> <p>The complete reference for <code>basic_json</code> and its member functions, types, and related classes.</p> <p> API documentation</p> </li> <li> <p> FAQ</p> <p>Answers to common questions and known surprises when using the library.</p> <p> FAQ</p> </li> <li> <p> Releases</p> <p>What changed in each release, with links to the relevant documentation.</p> <p> Releases</p> </li> <li> <p> Community</p> <p>The ecosystem, contribution guidelines, governance, and quality assurance around the project.</p> <p> Community</p> </li> </ul> <p>Unreleased changes</p> <p>This documentation is built from the <code>develop</code> branch and may describe changes that are not part of a release yet. Their version numbers are followed by an unreleased badge; see Releases for what shipped in each version.</p> <p>The library is licensed under the MIT License. The source code, issue tracker, and discussions are on GitHub.</p>"},{"location":"api/json/","title":"nlohmann::json","text":"<pre><code>using json = basic_json&lt;&gt;;\n</code></pre> <p>This type is the default specialization of the basic_json class which uses the standard template types.</p>"},{"location":"api/json/#examples","title":"Examples","text":"Example <p>The example below demonstrates how to use the type <code>nlohmann::json</code>.</p> <pre><code>#include &lt;iostream&gt;\n#include &lt;iomanip&gt;\n#include &lt;nlohmann/json.hpp&gt;\n\nusing json = nlohmann::json;\n\nint main()\n{\n // create a JSON object\n json j =\n {\n {\"pi\", 3.141},\n {\"happy\", true},\n {\"name\", \"Niels\"},\n {\"nothing\", nullptr},\n {\n \"answer\", {\n {\"everything\", 42}\n }\n },\n {\"list\", {1, 0, 2}},\n {\n \"object\", {\n {\"currency\", \"USD\"},\n {\"value\", 42.99}\n }\n }\n };\n\n // add new values\n j[\"new\"][\"key\"][\"value\"] = {\"another\", \"list\"};\n\n // count elements\n auto s = j.size();\n j[\"size\"] = s;\n\n // pretty print with indent of 4 spaces\n std::cout &lt;&lt; std::setw(4) &lt;&lt; j &lt;&lt; '\\n';\n}\n</code></pre> <p>Output:</p> <pre><code>{\n \"answer\": {\n \"everything\": 42\n },\n \"happy\": true,\n \"list\": [\n 1,\n 0,\n 2\n ],\n \"name\": \"Niels\",\n \"new\": {\n \"key\": {\n \"value\": [\n \"another\",\n Line truncated