xref: /llvm-project/libcxx/test/std/utilities/function.objects/logical.operations/logical_and.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 // logical_and
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     typedef std::logical_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<bool, F::result_type>::value), "" );
29 #endif
30     assert(f(36, 36));
31     assert(!f(36, 0));
32     assert(!f(0, 36));
33     assert(!f(0, 0));
34 #if TEST_STD_VER > 11
35     typedef std::logical_and<> F2;
36     const F2 f2 = F2();
37     assert( f2(36, 36));
38     assert( f2(36, 36L));
39     assert( f2(36L, 36));
40     assert(!f2(36, 0));
41     assert(!f2(0, 36));
42     assert( f2(36, 36L));
43     assert(!f2(36, 0L));
44     assert(!f2(0, 36L));
45     assert( f2(36L, 36));
46     assert(!f2(36L, 0));
47     assert(!f2(0L, 36));
48 
49     constexpr bool foo = std::logical_and<int> () (36, 36);
50     static_assert ( foo, "" );
51 
52     constexpr bool bar = std::logical_and<> () (36.0, 36);
53     static_assert ( bar, "" );
54 #endif
55 
56   return 0;
57 }
58