xref: /llvm-project/libcxx/test/std/utilities/type.index/type.index.members/cmp.pass.cpp (revision 9df58928045f2370caa201ba14d4ec62cba00e46)
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-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <typeindex>
10 
11 // class type_index
12 
13 // bool operator==(const type_index& rhs) const noexcept;
14 // bool operator!=(const type_index& rhs) const noexcept;
15 // bool operator< (const type_index& rhs) const noexcept;
16 // bool operator<=(const type_index& rhs) const noexcept;
17 // bool operator> (const type_index& rhs) const noexcept;
18 // bool operator>=(const type_index& rhs) const noexcept;
19 // strong_ordering operator<=>(const type_index& rhs) const noexcept;
20 
21 // UNSUPPORTED: no-rtti
22 
23 #include <typeindex>
24 #include <cassert>
25 
26 #include "test_macros.h"
27 #include "test_comparisons.h"
28 
main(int,char **)29 int main(int, char**) {
30   AssertComparisonsAreNoexcept<std::type_index>();
31   AssertComparisonsReturnBool<std::type_index>();
32 #if TEST_STD_VER > 17
33   AssertOrderAreNoexcept<std::type_index>();
34   AssertOrderReturn<std::strong_ordering, std::type_index>();
35 #endif
36 
37   std::type_index t1 = typeid(int);
38   std::type_index t2 = typeid(int);
39   std::type_index t3 = typeid(long);
40 
41   // Test `t1` and `t2` which should compare equal
42   assert(testComparisons(t1, t2, /*isEqual*/ true, /*isLess*/ false));
43 #if TEST_STD_VER > 17
44   assert(testOrder(t1, t2, std::strong_ordering::equal));
45 #endif
46 
47   // Test `t1` and `t3` which are not equal
48   bool is_less = t1 < t3;
49   assert(testComparisons(t1, t3, /*isEqual*/ false, is_less));
50 #if TEST_STD_VER > 17
51   assert(testOrder(t1, t3, is_less ? std::strong_ordering::less : std::strong_ordering::greater));
52 #endif
53 
54   return 0;
55 }
56