template-list.cc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // { dg-do run }
  2. #include <assert.h>
  3. extern "C" int printf(const char *, ...);
  4. class Subscriptor
  5. {
  6. public:
  7. Subscriptor() : counter(1) {}
  8. virtual ~Subscriptor()
  9. {
  10. counter--;
  11. assert(counter == 0);
  12. }
  13. private:
  14. mutable int counter;
  15. };
  16. template <int dim> struct Function
  17. {
  18. Function(int i): value(dim + i) {}
  19. int value;
  20. };
  21. template <int dim> struct Triangulation
  22. {
  23. };
  24. template <int dim> struct Exercise_2_3
  25. {
  26. enum { DIM = dim };
  27. };
  28. template <int dim>
  29. struct SetUpBase : public Subscriptor
  30. {
  31. virtual
  32. const Function<dim> get_boundary_values () const = 0;
  33. virtual
  34. const Function<dim> get_right_hand_side () const = 0;
  35. // virtual
  36. // void create_coarse_grid (Triangulation<dim> &coarse_grid) const = 0;
  37. };
  38. template <class Traits, int dim>
  39. struct SetUp : public SetUpBase<dim>
  40. {
  41. SetUp () {};
  42. virtual
  43. const Function<dim> get_boundary_values () const
  44. { return Function<dim>(Traits::DIM); }
  45. virtual
  46. const Function<dim> get_right_hand_side () const
  47. { return Function<dim>(Traits::DIM); }
  48. // virtual
  49. // void create_coarse_grid (Triangulation<dim> &coarse_grid) const;
  50. // static const typename Traits::BoundaryValues boundary_values;
  51. // static const typename Traits::RightHandSide right_hand_side;
  52. };
  53. int main()
  54. {
  55. /*
  56. SetUp<Exercise_2_3<1000>, 2> s1a;
  57. SetUp<Exercise_2_3<2000>, 1> s2;
  58. SetUp<Exercise_2_3<2000>, 2> s2a;
  59. return s1->get_boundary_values().value + s1a.get_boundary_values().value +
  60. s2.get_boundary_values().value + s2a.get_boundary_values().value +
  61. s1->get_right_hand_side().value + s1a.get_right_hand_side().value +
  62. s2.get_right_hand_side().value + s2a.get_right_hand_side().value;
  63. */
  64. #ifndef NFAIL
  65. SetUp<Exercise_2_3<1000>, 1> * s1 = new SetUp<Exercise_2_3<1000>, 1>();
  66. printf("%d\n", s1->get_boundary_values().value);
  67. return 0;
  68. #else
  69. SetUp<Exercise_2_3<1000>, 1> s1;
  70. printf("%d\n", s1.get_boundary_values().value);
  71. return 0;
  72. #endif
  73. }