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