跳转至

ev-json-spaceship-basic-json-003

字段 值
项目 nlohmann/json
固定 commit 55f93686c015
路径 include/nlohmann/json.hpp
行段 L3745-L3754
特性 三路比较运算符 <=>
许可证 MIT
代码来源 项目源码
级别 manual
审核 zyuhao7 @ 2026-10-24
测试代码 否
发现方式 tree-sitter

用法

为 basic_json 实现三路比较并保留无序结果

为什么典型

把类型序与值比较收进一个入口,其余关系运算符由重写获得,避免多处逻辑漂移。

摘录

    std::partial_ordering operator<=>(const_reference rhs) const noexcept // *NOPAD*
    {
        const_reference lhs = *this;
        // default_result is used if we cannot compare values. In that case,
        // we compare types.
        JSON_IMPLEMENT_OPERATOR(<=>, // *NOPAD*
                                std::partial_ordering::equivalent,
                                std::partial_ordering::unordered,
                                lhs_type <=> rhs_type) // *NOPAD*
    }

备注

生产路径;返回类型为 partial_ordering。

查看固定 commit 源码 · 返回证据索引