Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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 | |
Marshall Clow | 1b92188 | 2013-12-03 00:18:10 +0000 | [diff] [blame] | 19 | #include "test_allocator.h" |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 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 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 50 | int main() |
| 51 | { |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 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); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 60 | } |