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 
     16 #include <functional>
     17 #include <cassert>
     18 
     19 #include "../test_allocator.h"
     20 
     21 class A
     22 {
     23     int data_[10];
     24 public:
     25     static int count;
     26 
     27     A()
     28     {
     29         ++count;
     30         for (int i = 0; i < 10; ++i)
     31             data_[i] = i;
     32     }
     33 
     34     A(const A&) {++count;}
     35 
     36     ~A() {--count;}
     37 
     38     int operator()(int i) const
     39     {
     40         for (int j = 0; j < 10; ++j)
     41             i += data_[j];
     42         return i;
     43     }
     44 
     45     int foo(int) const {return 1;}
     46 };
     47 
     48 int A::count = 0;
     49 
     50 int main()
     51 {
     52     {
     53     std::function<int(int)> f;
     54     f.assign(A(), test_allocator<A>());
     55     assert(A::count == 1);
     56     assert(f.target<A>());
     57     assert(f.target<int(*)(int)>() == 0);
     58     }
     59     assert(A::count == 0);
     60 }
     61