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 // class function<R(ArgTypes...)>
12 
13 // template<class F, class A> void assign(F&&, const A&);
14 //     This call was removed post-C++14
15 
16 // This test runs in C++03, but we have deprecated using std::function in C++03.
17 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS -D_LIBCPP_ENABLE_CXX03_FUNCTION
18 
19 #include <functional>
20 #include <cassert>
21 
22 #include "test_macros.h"
23 #include "test_allocator.h"
24 
25 class A
26 {
27     int data_[10];
28 public:
29     static int count;
30 
A()31     A()
32     {
33         ++count;
34         for (int i = 0; i < 10; ++i)
35             data_[i] = i;
36     }
37 
A(const A &)38     A(const A&) {++count;}
39 
~A()40     ~A() {--count;}
41 
operator ()(int i) const42     int operator()(int i) const
43     {
44         for (int j = 0; j < 10; ++j)
45             i += data_[j];
46         return i;
47     }
48 
foo(int) const49     int foo(int) const {return 1;}
50 };
51 
52 int A::count = 0;
53 
main(int,char **)54 int main(int, char**)
55 {
56 #if TEST_STD_VER <= 14
57     {
58     std::function<int(int)> f;
59     f.assign(A(), test_allocator<A>());
60     assert(A::count == 1);
61     assert(f.target<A>());
62     assert(f.target<int(*)(int)>() == 0);
63     }
64     assert(A::count == 0);
65 #endif
66 
67   return 0;
68 }
69