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