相关疑难解决方法(0)

std::less<Pointer> 的严格全序

这个问题来自这个评论

如果有两个向量 a 和 b,则总顺序允许为 &a[0], &b[0], &a[1], &b[1], &a[2], &b[2], ... ,即元素交错。

该命令是否被允许?

我对标准了解不多。如果我只阅读与 直接相关的部分,这似乎是正确的std::less

我发现 Herb Sutter 的 gcpp 库有类似的用法(链接):

    //  Return whether p points into this page's storage and is allocated.
    //
    inline
    bool gpage::contains(gsl::not_null<const byte*> p) const noexcept {
        //  Use std::less<> to compare (possibly unrelated) pointers portably
        auto const cmp = std::less<>{};
        auto const ext = extent();
        return !cmp(p, ext.data()) && cmp(p, ext.data() + ext.size());
    }
Run Code Online (Sandbox Code Playgroud)

c++ comparison pointers language-lawyer

7
推荐指数
1
解决办法
248
查看次数

标签 统计

c++ ×1

comparison ×1

language-lawyer ×1

pointers ×1