Home | History | Annotate | Download | only in func.wrap.func.mod
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <functional>
     11 
     12 // class function<R(ArgTypes...)>
     13 
     14 // template<class F, class A> void assign(F&&, const A&);
     15 //     This call was removed post-C++14
     16 
     17 #include <functional>
     18 #include <cassert>
     19 
     20 #include "test_macros.h"
     21 #include "test_allocator.h"
     22 
     23 class A
     24 {
     25     int data_[10];
     26 public:
     27     static int count;
     28 
     29     A()
     30     {
     31         ++count;
     32         for (int i = 0; i < 10; ++i)
     33             data_[i] = i;
     34     }
     35 
     36     A(const A&) {++count;}
     37 
     38     ~A() {--count;}
     39 
     40     int operator()(int i) const
     41     {
     42         for (int j = 0; j < 10; ++j)
     43             i += data_[j];
     44         return i;
     45     }
     46 
     47     int foo(int) const {return 1;}
     48 };
     49 
     50 int A::count = 0;
     51 
     52 int main()
     53 {
     54 #if TEST_STD_VER <= 14
     55     {
     56     std::function<int(int)> f;
     57     f.assign(A(), test_allocator<A>());
     58     assert(A::count == 1);
     59     assert(f.target<A>());
     60     assert(f.target<int(*)(int)>() == 0);
     61     }
     62     assert(A::count == 0);
     63 #endif
     64 }
     65