Debian Codegraph @

libcxx/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_void_0.pass.cpp

raw
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
10
11 // <functional>
12
13 // template<CopyConstructible Fn, CopyConstructible... Types>
14 // unspecified bind(Fn, Types...);
15 // template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>
16 // unspecified bind(Fn, Types...);
17
18 #include <functional>
19 #include <cassert>
20
21 #include "test_macros.h"
22
23 int count = 0;
24
25 template <class F>
26 void
27 test(F f)
28 {
29 int save_count = count;
30 f();
31 assert(count == save_count + 1);
32 }
33
34 template <class F>
35 void
36 test_const(const F& f)
37 {
38 int save_count = count;
39 f();
40 assert(count == save_count + 2);
41 }
42
43 void f() {++count;}
44
45 int g() {++count; return 0;}
46
47 struct A_void_0
48 {
49 void operator()() {++count;}
50 void operator()() const {count += 2;}
51 };
52
53 struct A_int_0
54 {
55 int operator()() {++count; return 4;}
56 int operator()() const {count += 2; return 5;}
57 };
58
59 int main(int, char**)
60 {
61 test(std::bind(f));
62 test(std::bind(&f));
63 test(std::bind(A_void_0()));
64 test_const(std::bind(A_void_0()));
65
66 test(std::bind<void>(f));
67 test(std::bind<void>(&f));
68 test(std::bind<void>(A_void_0()));
69 test_const(std::bind<void>(A_void_0()));
70
71 test(std::bind<void>(g));
72 test(std::bind<void>(&g));
73 test(std::bind<void>(A_int_0()));
74 test_const(std::bind<void>(A_int_0()));
75
76 return 0;
77 }