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 // UNSUPPORTED: c++03, c++11
10 // <functional>
11
12 // bit_not
13
14 #include <functional>
15 #include <type_traits>
16 #include <cassert>
17
18 #include "test_macros.h"
19
main(int,char **)20 int main(int, char**)
21 {
22 typedef std::bit_not<int> F;
23 const F f = F();
24 static_assert((std::is_same<F::argument_type, int>::value), "" );
25 static_assert((std::is_same<F::result_type, int>::value), "" );
26 assert((f(0xEA95) & 0xFFFF ) == 0x156A);
27 assert((f(0x58D3) & 0xFFFF ) == 0xA72C);
28 assert((f(0) & 0xFFFF ) == 0xFFFF);
29 assert((f(0xFFFF) & 0xFFFF ) == 0);
30
31 typedef std::bit_not<> F2;
32 const F2 f2 = F2();
33 assert((f2(0xEA95) & 0xFFFF ) == 0x156A);
34 assert((f2(0xEA95L) & 0xFFFF ) == 0x156A);
35 assert((f2(0x58D3) & 0xFFFF ) == 0xA72C);
36 assert((f2(0x58D3L) & 0xFFFF ) == 0xA72C);
37 assert((f2(0) & 0xFFFF ) == 0xFFFF);
38 assert((f2(0L) & 0xFFFF ) == 0xFFFF);
39 assert((f2(0xFFFF) & 0xFFFF ) == 0);
40 assert((f2(0xFFFFL) & 0xFFFF ) == 0);
41
42 constexpr int foo = std::bit_not<int> () (0xEA95) & 0xFFFF;
43 static_assert ( foo == 0x156A, "" );
44
45 constexpr int bar = std::bit_not<> () (0xEA95) & 0xFFFF;
46 static_assert ( bar == 0x156A, "" );
47
48 return 0;
49 }
50