summaryrefslogtreecommitdiff
path: root/libcxx/test/std/language.support/cmp/compare.syn/named_functions.pass.cpp
blob: 1d31e555ab02660ed6abf769def0448068a7590a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++03, c++11, c++14, c++17

// <compare>

// constexpr bool is_eq  (partial_ordering cmp) noexcept { return cmp == 0; }
// constexpr bool is_neq (partial_ordering cmp) noexcept { return cmp != 0; }
// constexpr bool is_lt  (partial_ordering cmp) noexcept { return cmp < 0; }
// constexpr bool is_lteq(partial_ordering cmp) noexcept { return cmp <= 0; }
// constexpr bool is_gt  (partial_ordering cmp) noexcept { return cmp > 0; }
// constexpr bool is_gteq(partial_ordering cmp) noexcept { return cmp >= 0; }

#include <compare>
#include <cassert>

#include "test_macros.h"

constexpr bool test()
{
    assert(!std::is_eq(std::strong_ordering::less));
    assert( std::is_eq(std::strong_ordering::equal));
    assert(!std::is_eq(std::strong_ordering::greater));
    assert(!std::is_eq(std::weak_ordering::less));
    assert( std::is_eq(std::weak_ordering::equivalent));
    assert(!std::is_eq(std::weak_ordering::greater));
    assert(!std::is_eq(std::partial_ordering::less));
    assert( std::is_eq(std::partial_ordering::equivalent));
    assert(!std::is_eq(std::partial_ordering::greater));
    assert(!std::is_eq(std::partial_ordering::unordered));

    assert( std::is_neq(std::strong_ordering::less));
    assert(!std::is_neq(std::strong_ordering::equal));
    assert( std::is_neq(std::strong_ordering::greater));
    assert( std::is_neq(std::weak_ordering::less));
    assert(!std::is_neq(std::weak_ordering::equivalent));
    assert( std::is_neq(std::weak_ordering::greater));
    assert( std::is_neq(std::partial_ordering::less));
    assert(!std::is_neq(std::partial_ordering::equivalent));
    assert( std::is_neq(std::partial_ordering::greater));
    assert( std::is_neq(std::partial_ordering::unordered));

    assert( std::is_lt(std::strong_ordering::less));
    assert(!std::is_lt(std::strong_ordering::equal));
    assert(!std::is_lt(std::strong_ordering::greater));
    assert( std::is_lt(std::weak_ordering::less));
    assert(!std::is_lt(std::weak_ordering::equivalent));
    assert(!std::is_lt(std::weak_ordering::greater));
    assert( std::is_lt(std::partial_ordering::less));
    assert(!std::is_lt(std::partial_ordering::equivalent));
    assert(!std::is_lt(std::partial_ordering::greater));
    assert(!std::is_lt(std::partial_ordering::unordered));

    assert( std::is_lteq(std::strong_ordering::less));
    assert( std::is_lteq(std::strong_ordering::equal));
    assert(!std::is_lteq(std::strong_ordering::greater));
    assert( std::is_lteq(std::weak_ordering::less));
    assert( std::is_lteq(std::weak_ordering::equivalent));
    assert(!std::is_lteq(std::weak_ordering::greater));
    assert( std::is_lteq(std::partial_ordering::less));
    assert( std::is_lteq(std::partial_ordering::equivalent));
    assert(!std::is_lteq(std::partial_ordering::greater));
    assert(!std::is_lteq(std::partial_ordering::unordered));

    assert(!std::is_gt(std::strong_ordering::less));
    assert(!std::is_gt(std::strong_ordering::equal));
    assert( std::is_gt(std::strong_ordering::greater));
    assert(!std::is_gt(std::weak_ordering::less));
    assert(!std::is_gt(std::weak_ordering::equivalent));
    assert( std::is_gt(std::weak_ordering::greater));
    assert(!std::is_gt(std::partial_ordering::less));
    assert(!std::is_gt(std::partial_ordering::equivalent));
    assert( std::is_gt(std::partial_ordering::greater));
    assert(!std::is_gt(std::partial_ordering::unordered));

    assert(!std::is_gteq(std::strong_ordering::less));
    assert( std::is_gteq(std::strong_ordering::equal));
    assert( std::is_gteq(std::strong_ordering::greater));
    assert(!std::is_gteq(std::weak_ordering::less));
    assert( std::is_gteq(std::weak_ordering::equivalent));
    assert( std::is_gteq(std::weak_ordering::greater));
    assert(!std::is_gteq(std::partial_ordering::less));
    assert( std::is_gteq(std::partial_ordering::equivalent));
    assert( std::is_gteq(std::partial_ordering::greater));
    assert(!std::is_gteq(std::partial_ordering::unordered));

    // Test noexceptness.
    ASSERT_NOEXCEPT(std::is_eq(std::partial_ordering::less));
    ASSERT_NOEXCEPT(std::is_neq(std::partial_ordering::less));
    ASSERT_NOEXCEPT(std::is_lt(std::partial_ordering::less));
    ASSERT_NOEXCEPT(std::is_lteq(std::partial_ordering::less));
    ASSERT_NOEXCEPT(std::is_gt(std::partial_ordering::less));
    ASSERT_NOEXCEPT(std::is_gteq(std::partial_ordering::less));

    return true;
}

int main(int, char**) {
    test();
    static_assert(test());

    return 0;
}