1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-threads
15 // bool operator==(thread::id x, thread::id y) noexcept;
16 // bool operator!=(thread::id x, thread::id y) noexcept;
17 // bool operator< (thread::id x, thread::id y) noexcept;
18 // bool operator<=(thread::id x, thread::id y) noexcept;
19 // bool operator> (thread::id x, thread::id y) noexcept;
20 // bool operator>=(thread::id x, thread::id y) noexcept;
21 // strong_ordering operator<=>(thread::id x, thread::id y) noexcept;
26 #include "test_macros.h"
27 #include "test_comparisons.h"
29 int main(int, char**) {
30 AssertComparisonsAreNoexcept
<std::thread::id
>();
31 AssertComparisonsReturnBool
<std::thread::id
>();
33 AssertOrderAreNoexcept
<std::thread::id
>();
34 AssertOrderReturn
<std::strong_ordering
, std::thread::id
>();
39 std::thread::id id3
= std::this_thread::get_id();
41 // `id1` and `id2` should compare equal
42 assert(testComparisons(id1
, id2
, /*isEqual*/ true, /*isLess*/ false));
44 assert(testOrder(id1
, id2
, std::strong_ordering::equal
));
47 // Test `t1` and `t3` which are not equal
48 bool isLess
= id1
< id3
;
49 assert(testComparisons(id1
, id3
, /*isEqual*/ false, isLess
));
51 assert(testOrder(id1
, id3
, isLess
? std::strong_ordering::less
: std::strong_ordering::greater
));
54 // Regression tests for https://github.com/llvm/llvm-project/issues/56187
55 // libc++ previously declared the comparison operators as hidden friends
56 // which was non-conforming.
57 assert(std::operator==(id1
, id2
));
58 #if TEST_STD_VER <= 17
59 assert(!std::operator!=(id1
, id2
));
60 assert(!std::operator<(id1
, id2
));
61 assert(std::operator<=(id1
, id2
));
62 assert(!std::operator>(id1
, id2
));
63 assert(std::operator>=(id1
, id2
));
65 assert(std::operator<=>(id1
, id2
) == std::strong_ordering::equal
);