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// UNSUPPORTED: c++03, c++11, c++14, c++17
10
11// <compare>
12
13// constexpr bool is_eq (partial_ordering cmp) noexcept { return cmp == 0; }
14// constexpr bool is_neq (partial_ordering cmp) noexcept { return cmp != 0; }
15// constexpr bool is_lt (partial_ordering cmp) noexcept { return cmp < 0; }
16// constexpr bool is_lteq(partial_ordering cmp) noexcept { return cmp <= 0; }
17// constexpr bool is_gt (partial_ordering cmp) noexcept { return cmp > 0; }
18// constexpr bool is_gteq(partial_ordering cmp) noexcept { return cmp >= 0; }
19
20#include <compare>
21#include <cassert>
22
23#include "test_macros.h"
24
25constexpr bool test()
26{
27 assert(!std::is_eq(std::strong_ordering::less));
28 assert( std::is_eq(std::strong_ordering::equal));
29 assert(!std::is_eq(std::strong_ordering::greater));
30 assert(!std::is_eq(std::weak_ordering::less));
31 assert( std::is_eq(std::weak_ordering::equivalent));
32 assert(!std::is_eq(std::weak_ordering::greater));
33 assert(!std::is_eq(std::partial_ordering::less));
34 assert( std::is_eq(std::partial_ordering::equivalent));
35 assert(!std::is_eq(std::partial_ordering::greater));
36 assert(!std::is_eq(std::partial_ordering::unordered));
37
38 assert( std::is_neq(std::strong_ordering::less));
39 assert(!std::is_neq(std::strong_ordering::equal));
40 assert( std::is_neq(std::strong_ordering::greater));
41 assert( std::is_neq(std::weak_ordering::less));
42 assert(!std::is_neq(std::weak_ordering::equivalent));
43 assert( std::is_neq(std::weak_ordering::greater));
44 assert( std::is_neq(std::partial_ordering::less));
45 assert(!std::is_neq(std::partial_ordering::equivalent));
46 assert( std::is_neq(std::partial_ordering::greater));
47 assert( std::is_neq(std::partial_ordering::unordered));
48
49 assert( std::is_lt(std::strong_ordering::less));
50 assert(!std::is_lt(std::strong_ordering::equal));
51 assert(!std::is_lt(std::strong_ordering::greater));
52 assert( std::is_lt(std::weak_ordering::less));
53 assert(!std::is_lt(std::weak_ordering::equivalent));
54 assert(!std::is_lt(std::weak_ordering::greater));
55 assert( std::is_lt(std::partial_ordering::less));
56 assert(!std::is_lt(std::partial_ordering::equivalent));
57 assert(!std::is_lt(std::partial_ordering::greater));
58 assert(!std::is_lt(std::partial_ordering::unordered));
59
60 assert( std::is_lteq(std::strong_ordering::less));
61 assert( std::is_lteq(std::strong_ordering::equal));
62 assert(!std::is_lteq(std::strong_ordering::greater));
63 assert( std::is_lteq(std::weak_ordering::less));
64 assert( std::is_lteq(std::weak_ordering::equivalent));
65 assert(!std::is_lteq(std::weak_ordering::greater));
66 assert( std::is_lteq(std::partial_ordering::less));
67 assert( std::is_lteq(std::partial_ordering::equivalent));
68 assert(!std::is_lteq(std::partial_ordering::greater));
69 assert(!std::is_lteq(std::partial_ordering::unordered));
70
71 assert(!std::is_gt(std::strong_ordering::less));
72 assert(!std::is_gt(std::strong_ordering::equal));
73 assert( std::is_gt(std::strong_ordering::greater));
74 assert(!std::is_gt(std::weak_ordering::less));
75 assert(!std::is_gt(std::weak_ordering::equivalent));
76 assert( std::is_gt(std::weak_ordering::greater));
77 assert(!std::is_gt(std::partial_ordering::less));
78 assert(!std::is_gt(std::partial_ordering::equivalent));
79 assert( std::is_gt(std::partial_ordering::greater));
80 assert(!std::is_gt(std::partial_ordering::unordered));
81
82 assert(!std::is_gteq(std::strong_ordering::less));
83 assert( std::is_gteq(std::strong_ordering::equal));
84 assert( std::is_gteq(std::strong_ordering::greater));
85 assert(!std::is_gteq(std::weak_ordering::less));
86 assert( std::is_gteq(std::weak_ordering::equivalent));
87 assert( std::is_gteq(std::weak_ordering::greater));
88 assert(!std::is_gteq(std::partial_ordering::less));
89 assert( std::is_gteq(std::partial_ordering::equivalent));
90 assert( std::is_gteq(std::partial_ordering::greater));
91 assert(!std::is_gteq(std::partial_ordering::unordered));
92
93 // Test noexceptness.
94 ASSERT_NOEXCEPT(std::is_eq(std::partial_ordering::less));
95 ASSERT_NOEXCEPT(std::is_neq(std::partial_ordering::less));
96 ASSERT_NOEXCEPT(std::is_lt(std::partial_ordering::less));
97 ASSERT_NOEXCEPT(std::is_lteq(std::partial_ordering::less));
98 ASSERT_NOEXCEPT(std::is_gt(std::partial_ordering::less));
99 ASSERT_NOEXCEPT(std::is_gteq(std::partial_ordering::less));
100
101 return true;
102}
103
104int main(int, char**) {
105 test();
106 static_assert(test());
107
108 return 0;
109}
110

source code of libcxx/test/std/language.support/cmp/compare.syn/named_functions.pass.cpp