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
23int count = 0;
24
25template <class F>
26void
27test(F f)
28{
29 int save_count = count;
30 f();
31 assert(count == save_count + 1);
32}
33
34template <class F>
35void
36test_const(const F& f)
37{
38 int save_count = count;
39 f();
40 assert(count == save_count + 2);
41}
42
43void f() {++count;}
44
45int g() {++count; return 0;}
46
47struct A_void_0
48{
49 void operator()() {++count;}
50 void operator()() const {count += 2;}
51};
52
53struct A_int_0
54{
55 int operator()() {++count; return 4;}
56 int operator()() const {count += 2; return 5;}
57};
58
59int main(int, char**)
60{
61 test(f: std::bind(f&: f));
62 test(f: std::bind(f: &f));
63 test(f: std::bind(f: A_void_0()));
64 test_const(f: std::bind(f: A_void_0()));
65
66 test(f: std::bind<void>(f&: f));
67 test(f: std::bind<void>(f: &f));
68 test(f: std::bind<void>(f: A_void_0()));
69 test_const(f: std::bind<void>(f: A_void_0()));
70
71 test(f: std::bind<void>(f&: g));
72 test(f: std::bind<void>(f: &g));
73 test(f: std::bind<void>(f: A_int_0()));
74 test_const(f: std::bind<void>(f: A_int_0()));
75
76 return 0;
77}
78

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