xref: /llvm-project/libcxx/test/std/diagnostics/syserr/syserr.compare/cmp_error_condition.pass.cpp (revision 877620bd961851d1ce6891db591b193b85796027)
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 // UNSUPPORTED: c++03, c++11, c++14, c++17
9 
10 // <system_error>
11 
12 // class error_condition
13 
14 // strong_ordering operator<=>(const error_condition& lhs, const error_condition& rhs) noexcept
15 
16 #include <system_error>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 #include "test_comparisons.h"
21 
main(int,char **)22 int main(int, char**) {
23   AssertOrderAreNoexcept<std::error_condition>();
24   AssertOrderReturn<std::strong_ordering, std::error_condition>();
25 
26   // Same error category
27   std::error_condition ec1a = std::error_condition(1, std::generic_category());
28   std::error_condition ec1b = std::error_condition(1, std::generic_category());
29   std::error_condition ec2  = std::error_condition(2, std::generic_category());
30 
31   assert(testOrder(ec1a, ec1b, std::strong_ordering::equal));
32   assert(testOrder(ec1a, ec2, std::strong_ordering::less));
33 
34   // Different error category
35   const std::error_condition& ec3 = std::error_condition(2, std::system_category());
36 
37   bool isLess = ec2 < ec3;
38   assert(testOrder(ec2, ec3, isLess ? std::strong_ordering::less : std::strong_ordering::greater));
39 
40   return 0;
41 }
42