]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/18_support/comparisons/algorithms/partial_order.cc
1 // Copyright (C) 2019-2024 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-do run { target c++20 } }
22 #include <testsuite_hooks.h>
24 using std::partial_order
;
25 using std::partial_ordering
;
30 const int one
= 1, two
= 2;
32 static_assert( partial_order(one
, two
) == partial_ordering::less
);
33 static_assert( partial_order(one
, one
) == partial_ordering::equivalent
);
34 static_assert( partial_order(two
, one
) == partial_ordering::greater
);
35 static_assert( noexcept(partial_order(1, 1)) );
38 constexpr partial_ordering
different_cv_quals(int i
, const int j
)
40 return partial_order(i
, j
);
46 const int fortytwo
= 42, nines
= 999, lots
= 1000;
47 static_assert( different_cv_quals(fortytwo
, nines
) == partial_ordering::less
);
48 static_assert( different_cv_quals(-nines
, -nines
) == partial_ordering::equivalent
);
49 static_assert( different_cv_quals(-nines
, -lots
) == partial_ordering::greater
);
55 constexpr double zero
= 0.0;
56 static_assert( partial_order(zero
, zero
) == partial_ordering::equivalent
);
57 static_assert( partial_order(-zero
, -zero
) == partial_ordering::equivalent
);
58 static_assert( partial_order(-zero
, zero
) == partial_ordering::equivalent
);
59 static_assert( partial_order(zero
, -zero
) == partial_ordering::equivalent
);
60 static_assert( noexcept(partial_order(zero
, 1.0)) );
61 static_assert( partial_order(0.0, 1.0) == std::partial_ordering::less
);
63 constexpr double min
= std::numeric_limits
<double>::lowest();
64 constexpr double max
= std::numeric_limits
<double>::max();
65 constexpr double nan
= std::numeric_limits
<double>::quiet_NaN();
66 constexpr double inf
= std::numeric_limits
<double>::infinity();
67 constexpr double denorm
= std::numeric_limits
<double>::denorm_min();
68 constexpr double smallest
= std::numeric_limits
<double>::min();
69 constexpr double epsilon
= std::numeric_limits
<double>::epsilon();
70 static_assert( partial_order(denorm
, smallest
) == partial_ordering::less
);
71 static_assert( partial_order(denorm
, 0.0) == partial_ordering::greater
);
72 // FIXME: these should all use static_assert. See PR88173.
73 VERIFY( partial_order(0.0, nan
) == partial_ordering::unordered
);
74 VERIFY( partial_order(nan
, nan
) == partial_ordering::unordered
);
75 VERIFY( partial_order(nan
, 0.0) == partial_ordering::unordered
);
76 VERIFY( partial_order(-nan
, 0.0) == partial_ordering::unordered
);
77 VERIFY( partial_order(-nan
, min
) == partial_ordering::unordered
);
78 static_assert( partial_order(-inf
, min
) == partial_ordering::less
);
79 VERIFY( partial_order(-nan
, -inf
) == partial_ordering::unordered
);
80 VERIFY( partial_order(-inf
, -nan
) == partial_ordering::unordered
);
81 static_assert( partial_order(max
, inf
) == partial_ordering::less
);
82 static_assert( partial_order(inf
, max
) == partial_ordering::greater
);
83 VERIFY( partial_order(inf
, nan
) == partial_ordering::unordered
);
84 static_assert( partial_order(1.0, 1.0+epsilon
) == partial_ordering::less
);
91 constexpr partial_ordering
operator<=>(X l
, X r
)
93 if (l
.i
< 0 && r
.i
< 0)
94 return partial_ordering::equivalent
;
98 constexpr bool operator==(X l
, X r
) { return std::is_eq(l
<=> r
); }
100 static_assert(std::three_way_comparable
<X
>);
110 // FIXME: these should all use static_assert
111 VERIFY( partial_order(one
, X
{1}) == partial_ordering::equivalent
);
112 VERIFY( partial_order(negone
, X
{-2}) == partial_ordering::equivalent
);
113 VERIFY( partial_order(one
, X
{2}) == partial_ordering::greater
);
114 static_assert( !noexcept(partial_order(X
{1}, X
{2})) );