xref: /llvm-project/libcxx/test/std/language.support/cmp/compare.syn/named_functions.pass.cpp (revision 969359e3b86b6cd238bcb48cdaeb9be5dbeddb4b)
1*969359e3SArthur O'Dwyer //===----------------------------------------------------------------------===//
2*969359e3SArthur O'Dwyer //
3*969359e3SArthur O'Dwyer // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*969359e3SArthur O'Dwyer // See https://llvm.org/LICENSE.txt for license information.
5*969359e3SArthur O'Dwyer // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*969359e3SArthur O'Dwyer //
7*969359e3SArthur O'Dwyer //===----------------------------------------------------------------------===//
8*969359e3SArthur O'Dwyer 
9*969359e3SArthur O'Dwyer // UNSUPPORTED: c++03, c++11, c++14, c++17
10*969359e3SArthur O'Dwyer 
11*969359e3SArthur O'Dwyer // <compare>
12*969359e3SArthur O'Dwyer 
13*969359e3SArthur O'Dwyer // constexpr bool is_eq  (partial_ordering cmp) noexcept { return cmp == 0; }
14*969359e3SArthur O'Dwyer // constexpr bool is_neq (partial_ordering cmp) noexcept { return cmp != 0; }
15*969359e3SArthur O'Dwyer // constexpr bool is_lt  (partial_ordering cmp) noexcept { return cmp < 0; }
16*969359e3SArthur O'Dwyer // constexpr bool is_lteq(partial_ordering cmp) noexcept { return cmp <= 0; }
17*969359e3SArthur O'Dwyer // constexpr bool is_gt  (partial_ordering cmp) noexcept { return cmp > 0; }
18*969359e3SArthur O'Dwyer // constexpr bool is_gteq(partial_ordering cmp) noexcept { return cmp >= 0; }
19*969359e3SArthur O'Dwyer 
20*969359e3SArthur O'Dwyer #include <compare>
21*969359e3SArthur O'Dwyer #include <cassert>
22*969359e3SArthur O'Dwyer 
23*969359e3SArthur O'Dwyer #include "test_macros.h"
24*969359e3SArthur O'Dwyer 
test()25*969359e3SArthur O'Dwyer constexpr bool test()
26*969359e3SArthur O'Dwyer {
27*969359e3SArthur O'Dwyer     assert(!std::is_eq(std::strong_ordering::less));
28*969359e3SArthur O'Dwyer     assert( std::is_eq(std::strong_ordering::equal));
29*969359e3SArthur O'Dwyer     assert(!std::is_eq(std::strong_ordering::greater));
30*969359e3SArthur O'Dwyer     assert(!std::is_eq(std::weak_ordering::less));
31*969359e3SArthur O'Dwyer     assert( std::is_eq(std::weak_ordering::equivalent));
32*969359e3SArthur O'Dwyer     assert(!std::is_eq(std::weak_ordering::greater));
33*969359e3SArthur O'Dwyer     assert(!std::is_eq(std::partial_ordering::less));
34*969359e3SArthur O'Dwyer     assert( std::is_eq(std::partial_ordering::equivalent));
35*969359e3SArthur O'Dwyer     assert(!std::is_eq(std::partial_ordering::greater));
36*969359e3SArthur O'Dwyer     assert(!std::is_eq(std::partial_ordering::unordered));
37*969359e3SArthur O'Dwyer 
38*969359e3SArthur O'Dwyer     assert( std::is_neq(std::strong_ordering::less));
39*969359e3SArthur O'Dwyer     assert(!std::is_neq(std::strong_ordering::equal));
40*969359e3SArthur O'Dwyer     assert( std::is_neq(std::strong_ordering::greater));
41*969359e3SArthur O'Dwyer     assert( std::is_neq(std::weak_ordering::less));
42*969359e3SArthur O'Dwyer     assert(!std::is_neq(std::weak_ordering::equivalent));
43*969359e3SArthur O'Dwyer     assert( std::is_neq(std::weak_ordering::greater));
44*969359e3SArthur O'Dwyer     assert( std::is_neq(std::partial_ordering::less));
45*969359e3SArthur O'Dwyer     assert(!std::is_neq(std::partial_ordering::equivalent));
46*969359e3SArthur O'Dwyer     assert( std::is_neq(std::partial_ordering::greater));
47*969359e3SArthur O'Dwyer     assert( std::is_neq(std::partial_ordering::unordered));
48*969359e3SArthur O'Dwyer 
49*969359e3SArthur O'Dwyer     assert( std::is_lt(std::strong_ordering::less));
50*969359e3SArthur O'Dwyer     assert(!std::is_lt(std::strong_ordering::equal));
51*969359e3SArthur O'Dwyer     assert(!std::is_lt(std::strong_ordering::greater));
52*969359e3SArthur O'Dwyer     assert( std::is_lt(std::weak_ordering::less));
53*969359e3SArthur O'Dwyer     assert(!std::is_lt(std::weak_ordering::equivalent));
54*969359e3SArthur O'Dwyer     assert(!std::is_lt(std::weak_ordering::greater));
55*969359e3SArthur O'Dwyer     assert( std::is_lt(std::partial_ordering::less));
56*969359e3SArthur O'Dwyer     assert(!std::is_lt(std::partial_ordering::equivalent));
57*969359e3SArthur O'Dwyer     assert(!std::is_lt(std::partial_ordering::greater));
58*969359e3SArthur O'Dwyer     assert(!std::is_lt(std::partial_ordering::unordered));
59*969359e3SArthur O'Dwyer 
60*969359e3SArthur O'Dwyer     assert( std::is_lteq(std::strong_ordering::less));
61*969359e3SArthur O'Dwyer     assert( std::is_lteq(std::strong_ordering::equal));
62*969359e3SArthur O'Dwyer     assert(!std::is_lteq(std::strong_ordering::greater));
63*969359e3SArthur O'Dwyer     assert( std::is_lteq(std::weak_ordering::less));
64*969359e3SArthur O'Dwyer     assert( std::is_lteq(std::weak_ordering::equivalent));
65*969359e3SArthur O'Dwyer     assert(!std::is_lteq(std::weak_ordering::greater));
66*969359e3SArthur O'Dwyer     assert( std::is_lteq(std::partial_ordering::less));
67*969359e3SArthur O'Dwyer     assert( std::is_lteq(std::partial_ordering::equivalent));
68*969359e3SArthur O'Dwyer     assert(!std::is_lteq(std::partial_ordering::greater));
69*969359e3SArthur O'Dwyer     assert(!std::is_lteq(std::partial_ordering::unordered));
70*969359e3SArthur O'Dwyer 
71*969359e3SArthur O'Dwyer     assert(!std::is_gt(std::strong_ordering::less));
72*969359e3SArthur O'Dwyer     assert(!std::is_gt(std::strong_ordering::equal));
73*969359e3SArthur O'Dwyer     assert( std::is_gt(std::strong_ordering::greater));
74*969359e3SArthur O'Dwyer     assert(!std::is_gt(std::weak_ordering::less));
75*969359e3SArthur O'Dwyer     assert(!std::is_gt(std::weak_ordering::equivalent));
76*969359e3SArthur O'Dwyer     assert( std::is_gt(std::weak_ordering::greater));
77*969359e3SArthur O'Dwyer     assert(!std::is_gt(std::partial_ordering::less));
78*969359e3SArthur O'Dwyer     assert(!std::is_gt(std::partial_ordering::equivalent));
79*969359e3SArthur O'Dwyer     assert( std::is_gt(std::partial_ordering::greater));
80*969359e3SArthur O'Dwyer     assert(!std::is_gt(std::partial_ordering::unordered));
81*969359e3SArthur O'Dwyer 
82*969359e3SArthur O'Dwyer     assert(!std::is_gteq(std::strong_ordering::less));
83*969359e3SArthur O'Dwyer     assert( std::is_gteq(std::strong_ordering::equal));
84*969359e3SArthur O'Dwyer     assert( std::is_gteq(std::strong_ordering::greater));
85*969359e3SArthur O'Dwyer     assert(!std::is_gteq(std::weak_ordering::less));
86*969359e3SArthur O'Dwyer     assert( std::is_gteq(std::weak_ordering::equivalent));
87*969359e3SArthur O'Dwyer     assert( std::is_gteq(std::weak_ordering::greater));
88*969359e3SArthur O'Dwyer     assert(!std::is_gteq(std::partial_ordering::less));
89*969359e3SArthur O'Dwyer     assert( std::is_gteq(std::partial_ordering::equivalent));
90*969359e3SArthur O'Dwyer     assert( std::is_gteq(std::partial_ordering::greater));
91*969359e3SArthur O'Dwyer     assert(!std::is_gteq(std::partial_ordering::unordered));
92*969359e3SArthur O'Dwyer 
93*969359e3SArthur O'Dwyer     // Test noexceptness.
94*969359e3SArthur O'Dwyer     ASSERT_NOEXCEPT(std::is_eq(std::partial_ordering::less));
95*969359e3SArthur O'Dwyer     ASSERT_NOEXCEPT(std::is_neq(std::partial_ordering::less));
96*969359e3SArthur O'Dwyer     ASSERT_NOEXCEPT(std::is_lt(std::partial_ordering::less));
97*969359e3SArthur O'Dwyer     ASSERT_NOEXCEPT(std::is_lteq(std::partial_ordering::less));
98*969359e3SArthur O'Dwyer     ASSERT_NOEXCEPT(std::is_gt(std::partial_ordering::less));
99*969359e3SArthur O'Dwyer     ASSERT_NOEXCEPT(std::is_gteq(std::partial_ordering::less));
100*969359e3SArthur O'Dwyer 
101*969359e3SArthur O'Dwyer     return true;
102*969359e3SArthur O'Dwyer }
103*969359e3SArthur O'Dwyer 
main(int,char **)104*969359e3SArthur O'Dwyer int main(int, char**) {
105*969359e3SArthur O'Dwyer     test();
106*969359e3SArthur O'Dwyer     static_assert(test());
107*969359e3SArthur O'Dwyer 
108*969359e3SArthur O'Dwyer     return 0;
109*969359e3SArthur O'Dwyer }
110