1 // Copyright (C) 2019 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-options "-std=gnu++2a" }
19 // { dg-do run { target c++2a } }
23 #include <testsuite_hooks.h>
25 using std::weak_order
;
26 using std::weak_ordering
;
33 VERIFY( weak_order(one
, two
) == weak_ordering::less
);
34 VERIFY( weak_order(one
, one
) == weak_ordering::equivalent
);
35 VERIFY( weak_order(two
, one
) == weak_ordering::greater
);
36 static_assert( noexcept(weak_order(1, 1)) );
39 constexpr weak_ordering
different_cv_quals(int i
, const int j
)
41 return weak_order(i
, j
);
47 int fortytwo
= 42, nines
= 999, lots
= 1000;
49 VERIFY( different_cv_quals(fortytwo
, nines
) == weak_ordering::less
);
50 VERIFY( different_cv_quals(-nines
, -nines
) == weak_ordering::equivalent
);
51 VERIFY( different_cv_quals(-nines
, -lots
) == weak_ordering::greater
);
58 VERIFY( weak_order(zero
, zero
) == weak_ordering::equivalent
);
59 VERIFY( weak_order(-zero
, -zero
) == weak_ordering::equivalent
);
60 VERIFY( weak_order(-zero
, zero
) == weak_ordering::equivalent
);
61 VERIFY( weak_order(zero
, -zero
) == weak_ordering::equivalent
);
63 double min
= std::numeric_limits
<double>::lowest();
64 double max
= std::numeric_limits
<double>::max();
65 double nan
= std::numeric_limits
<double>::quiet_NaN();
66 double inf
= std::numeric_limits
<double>::infinity();
67 double denorm
= std::numeric_limits
<double>::denorm_min();
68 double smallest
= std::numeric_limits
<double>::min();
69 double epsilon
= std::numeric_limits
<double>::epsilon();
70 VERIFY( weak_order(denorm
, smallest
) == weak_ordering::less
);
71 VERIFY( weak_order(denorm
, 0.0) == weak_ordering::greater
);
72 VERIFY( weak_order(0.0, nan
) == weak_ordering::less
);
73 VERIFY( weak_order(nan
, nan
) == weak_ordering::equivalent
);
74 VERIFY( weak_order(nan
, -nan
) == weak_ordering::greater
);
75 VERIFY( weak_order(-nan
, nan
) == weak_ordering::less
);
76 VERIFY( weak_order(nan
, 0.0) == weak_ordering::greater
);
77 VERIFY( weak_order(-nan
, 0.0) == weak_ordering::less
);
78 VERIFY( weak_order(-nan
, min
) == weak_ordering::less
);
79 VERIFY( weak_order(-inf
, min
) == weak_ordering::less
);
80 VERIFY( weak_order(-nan
, -inf
) == weak_ordering::less
);
81 VERIFY( weak_order(-inf
, -nan
) == weak_ordering::greater
);
82 VERIFY( weak_order(max
, inf
) == weak_ordering::less
);
83 VERIFY( weak_order(inf
, max
) == weak_ordering::greater
);
84 VERIFY( weak_order(inf
, nan
) == weak_ordering::less
);
85 VERIFY( weak_order(1.0, 1.0+epsilon
) == weak_ordering::less
);
92 constexpr weak_ordering
operator<=>(X l
, X r
)
94 if (l
.i
< 0 && r
.i
< 0)
95 return weak_ordering::equivalent
;
107 VERIFY( weak_order(one
, X
{1}) == weak_ordering::equivalent
);
108 VERIFY( weak_order(negone
, X
{-2}) == weak_ordering::equivalent
);
109 VERIFY( weak_order(one
, X
{2}) == weak_ordering::greater
);
110 static_assert( !noexcept(weak_order(X
{1}, X
{2})) );