xref: /llvm-project/libcxx/test/std/utilities/function.objects/bitwise.operations/bit_xor.pass.cpp (revision dc066888bd98c0500ca7b590317dc91ccce0fd38)
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 
9 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
10 
11 // <functional>
12 
13 // bit_xor
14 
15 #include <functional>
16 #include <type_traits>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 
main(int,char **)21 int main(int, char**)
22 {
23     {
24     typedef std::bit_xor<int> F;
25     const F f = F();
26 #if TEST_STD_VER <= 17
27     static_assert((std::is_same<int, F::first_argument_type>::value), "" );
28     static_assert((std::is_same<int, F::second_argument_type>::value), "" );
29     static_assert((std::is_same<int, F::result_type>::value), "" );
30 #endif
31     assert(f(0xEA95, 0xEA95) == 0);
32     assert(f(0xEA95, 0x58D3) == 0xB246);
33     assert(f(0x58D3, 0xEA95) == 0xB246);
34     assert(f(0x58D3, 0) == 0x58D3);
35     assert(f(0xFFFF, 0x58D3) == 0xA72C);
36     }
37 #if TEST_STD_VER > 11
38     {
39     typedef std::bit_xor<> F2;
40     const F2 f = F2();
41     assert(f(0xEA95, 0xEA95) == 0);
42     assert(f(0xEA95L, 0xEA95) == 0);
43     assert(f(0xEA95, 0xEA95L) == 0);
44 
45     assert(f(0xEA95, 0x58D3) == 0xB246);
46     assert(f(0xEA95L, 0x58D3) == 0xB246);
47     assert(f(0xEA95, 0x58D3L) == 0xB246);
48 
49     assert(f(0x58D3, 0xEA95) == 0xB246);
50     assert(f(0x58D3L, 0xEA95) == 0xB246);
51     assert(f(0x58D3, 0xEA95L) == 0xB246);
52 
53     assert(f(0x58D3, 0) == 0x58D3);
54     assert(f(0x58D3L, 0) == 0x58D3);
55     assert(f(0x58D3, 0L) == 0x58D3);
56 
57     assert(f(0xFFFF, 0x58D3) == 0xA72C);
58     assert(f(0xFFFFL, 0x58D3) == 0xA72C);
59     assert(f(0xFFFF, 0x58D3L) == 0xA72C);
60 
61     constexpr int foo = std::bit_xor<int> () (0x58D3, 0xEA95);
62     static_assert ( foo == 0xB246, "" );
63 
64     constexpr int bar = std::bit_xor<> () (0x58D3L, 0xEA95);
65     static_assert ( bar == 0xB246, "" );
66     }
67 #endif
68 
69   return 0;
70 }
71