70 lines · cpp
1//===----------------------------------------------------------------------===//2//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-exception6//7//===----------------------------------------------------------------------===//8//9// UNSUPPORTED: no-threads10 11// <thread>12 13// class thread::id14 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;22 23#include <thread>24#include <cassert>25 26#include "test_macros.h"27#include "test_comparisons.h"28 29int main(int, char**) {30 AssertComparisonsAreNoexcept<std::thread::id>();31 AssertComparisonsReturnBool<std::thread::id>();32#if TEST_STD_VER > 1733 AssertOrderAreNoexcept<std::thread::id>();34 AssertOrderReturn<std::strong_ordering, std::thread::id>();35#endif36 37 std::thread::id id1;38 std::thread::id id2;39 std::thread::id id3 = std::this_thread::get_id();40 41 // `id1` and `id2` should compare equal42 assert(testComparisons(id1, id2, /*isEqual*/ true, /*isLess*/ false));43#if TEST_STD_VER > 1744 assert(testOrder(id1, id2, std::strong_ordering::equal));45#endif46 47 // Test `t1` and `t3` which are not equal48 bool isLess = id1 < id3;49 assert(testComparisons(id1, id3, /*isEqual*/ false, isLess));50#if TEST_STD_VER > 1751 assert(testOrder(id1, id3, isLess ? std::strong_ordering::less : std::strong_ordering::greater));52#endif53 54 // Regression tests for https://llvm.org/PR5618755 // libc++ previously declared the comparison operators as hidden friends56 // which was non-conforming.57 assert(std::operator==(id1, id2));58#if TEST_STD_VER <= 1759 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));64#else65 assert(std::operator<=>(id1, id2) == std::strong_ordering::equal);66#endif67 68 return 0;69}70