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