相关疑难解决方法(0)

C++20 行为用相等运算符破坏现有代码?

我在调试这个问题时遇到了这个问题

我一直将其精简为仅使用Boost Operators

  1. 编译器资源管理器C++17 C++20

    #include <boost/operators.hpp>
    
    struct F : boost::totally_ordered1<F, boost::totally_ordered2<F, int>> {
        /*implicit*/ F(int t_) : t(t_) {}
        bool operator==(F const& o) const { return t == o.t; }
        bool operator< (F const& o) const { return t <  o.t; }
      private: int t;
    };
    
    int main() {
        #pragma GCC diagnostic ignored "-Wunused"
        F { 42 } == F{ 42 }; // OKAY
        42 == F{42};         // C++17 OK, C++20 infinite …
    Run Code Online (Sandbox Code Playgroud)

c++ spaceship-operator c++17 c++20

107
推荐指数
1
解决办法
4526
查看次数

标签 统计

c++ ×1

c++17 ×1

c++20 ×1

spaceship-operator ×1