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