Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-104108

As a user of QTestLib, I want to use QCOMPARE_op with C++20's spaceship operator <=>

XMLWordPrintable

    • Icon: User Story User Story
    • Resolution: Fixed
    • Icon: P2: Important P2: Important
    • 6.9.0 FF
    • None
    • Testing: qtestlib
    • None
    • 5
    • Foundation Sprint 108, Foundation Sprint 109, Foundation Sprint 110, Foundation Sprint 111, Foundation Sprint 112, Foundation Sprint 113, Foundation Sprint 114, Foundation Sprint 115, Foundation Sprint 116, Foundation Sprint 117, Foundation Sprint 118, Foundation Sprint 119, Foundation Sprint 120
    • 454f010e5 (dev)

      Following the implementation of QTBUG-98873, I would also like a QCOMPARE macro that tests my C++20 spaceship operators <=>. It's tedious to use the moral equivalents of

      QVERIFY((a <=> b) == r);
      QCOMPARE(a <=> b, r);
      

      esp since the std::*_ordering types don't support comparing two objects of their type with each other.

      Locally, I have defined me a

      #define COMPARE_3WAY(a, b, r) \
          do {  \
              static_assert(std::is_same_v<decltype((a) <=> (b)), decltype(r)>) ; \
              const auto actual = (a) <=> (b); \
              QCOMPARE(std::is_eq(actual), std::is_eq(r); \
              QCOMPARE(std::is_lt(actual), std::is_lt(r); \
              QCOMPARE(std::is_gt(actual), std::is_gt(r); \
         } while (0)
      

      But that, of course, doesn't output the values of a, b, and r upon failure, and doesn't work with strong_ordering::equivalent).

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            tatiana.borisova Tatiana Borisova
            mmutz Marc Mutz
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: