xref: /llvm-project/libcxx/test/std/utilities/function.objects/logical.operations/logical_and.pass.cpp (revision 57b08b0944046a6a57ee9b7b479181f548a5b9b4)
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 // logical_and
12 
13 #include <functional>
14 #include <type_traits>
15 #include <cassert>
16 
17 #include "test_macros.h"
18 
19 int main()
20 {
21     typedef std::logical_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<bool, F::result_type>::value), "" );
26     assert(f(36, 36));
27     assert(!f(36, 0));
28     assert(!f(0, 36));
29     assert(!f(0, 0));
30 #if TEST_STD_VER > 11
31     typedef std::logical_and<> F2;
32     const F2 f2 = F2();
33     assert( f2(36, 36));
34     assert( f2(36, 36L));
35     assert( f2(36L, 36));
36     assert(!f2(36, 0));
37     assert(!f2(0, 36));
38     assert( f2(36, 36L));
39     assert(!f2(36, 0L));
40     assert(!f2(0, 36L));
41     assert( f2(36L, 36));
42     assert(!f2(36L, 0));
43     assert(!f2(0L, 36));
44 
45     constexpr bool foo = std::logical_and<int> () (36, 36);
46     static_assert ( foo, "" );
47 
48     constexpr bool bar = std::logical_and<> () (36.0, 36);
49     static_assert ( bar, "" );
50 #endif
51 }
52