assign_F_alloc.pass.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // <functional>
  10. // class function<R(ArgTypes...)>
  11. // template<class F, class A> void assign(F&&, const A&);
  12. #include <functional>
  13. #include <cassert>
  14. #include "../test_allocator.h"
  15. class A
  16. {
  17. int data_[10];
  18. public:
  19. static int count;
  20. A()
  21. {
  22. ++count;
  23. for (int i = 0; i < 10; ++i)
  24. data_[i] = i;
  25. }
  26. A(const A&) {++count;}
  27. ~A() {--count;}
  28. int operator()(int i) const
  29. {
  30. for (int j = 0; j < 10; ++j)
  31. i += data_[j];
  32. return i;
  33. }
  34. int foo(int) const {return 1;}
  35. };
  36. int A::count = 0;
  37. int main()
  38. {
  39. {
  40. std::function<int(int)> f;
  41. f.assign(A(), test_allocator<A>());
  42. assert(A::count == 1);
  43. assert(f.target<A>());
  44. assert(f.target<int(*)(int)>() == 0);
  45. }
  46. assert(A::count == 0);
  47. }