</code></pre></div><p>This macro enables the (incorrect) legacy comparison behavior of discarded JSON values. Possible values are <code>1</code> to enable or <code>0</code> to disable (default).</p><p>When enabled, comparisons involving at least one discarded JSON value yield results as follows:</p><table><thead><tr><th><strong>Operator</strong></th><th><strong>Result</strong></th></tr></thead><tbody><tr><td><code>==</code></td><td><codeclass=highlight><spanclass=nb>false</span></code></td></tr><tr><td><code>!=</code></td><td><codeclass=highlight><spanclass=nb>true</span></code></td></tr><tr><td><code><</code></td><td><codeclass=highlight><spanclass=nb>false</span></code></td></tr><tr><td><code><=</code></td><td><codeclass=highlight><spanclass=nb>true</span></code></td></tr><tr><td><code>>=</code></td><td><codeclass=highlight><spanclass=nb>true</span></code></td></tr><tr><td><code>></code></td><td><codeclass=highlight><spanclass=nb>false</span></code></td></tr></tbody></table><p>Otherwise, comparisons involving at least one discarded JSON value always yield <codeclass=highlight><spanclass=nb>false</span></code>.</p><h2id=default-definition>Default definition<aclass=headerlinkhref=#default-definitiontitle="Permanent link">¶</a></h2><p>The default value is <code>0</code>.</p><divclass=highlight><pre><span></span><code><spanclass=cp>#define JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 0</span>
</code></pre></div><p>When the macro is not defined, the library will define it to its default value.</p><h2id=notes>Notes<aclass=headerlinkhref=#notestitle="Permanent link">¶</a></h2><divclass="admonition warning"><pclass=admonition-title>Inconsistent behavior in C++20 and beyond</p><p>When targeting C++20 or above, enabling the legacy comparison behavior is <em>strongly</em> discouraged.</p><ul><li>The 3-way comparison operator (<code><=></code>) will always give the correct result (<codeclass=highlight><spanclass=n>std</span><spanclass=o>::</span><spanclass=n>partial_ordering</span><spanclass=o>::</span><spanclass=n>unordered</span></code>) regardless of the value of <code>JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON</code>.</li><li>Overloads for the equality and relational operators emulate the legacy behavior.</li></ul><p>Code outside your control may use either 3-way comparison or the equality and relational operators, resulting in inconsistent and unpredictable behavior.</p><p>See <ahref=../../basic_json/operator_spaceship/><code>operator<=></code></a> for more information on 3-way comparison.</p></div><divclass="admonition warning"><pclass=admonition-title>Deprecation</p><p>The legacy comparison behavior is deprecated and may be removed in a future major version release.</p><p>New code should not depend on it and existing code should try to remove or rewrite expressions relying on it.</p></div><divclass="admonition hint"><pclass=admonition-title>CMake option</p><p>Legacy comparison can also be controlled with the CMake option <ahref=../../../integration/cmake/#json_legacydiscardedvaluecomparison><code>JSON_LegacyDiscardedValueComparison</code></a> (<code>OFF</code> by default) which defines <code>JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON</code> accordingly.</p></div><h2id=examples>Examples<aclass=headerlinkhref=#examplestitle="Permanent link">¶</a></h2><detailsclass=example><summary>Example</summary><p>The code below switches on the legacy discarded value comparison behavior in the library.</p><divclass=highlight><pre><span></span><code><spanclass=cp>#define JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 1</span>