1// { dg-do run } 2 3#include <assert.h> 4#include <iostream> 5#include <fstream> 6 7using std::ofstream; 8using std::ifstream; 9using std::ios; 10 11extern "C" int printf(const char *, ...); 12 13class Subscriptor 14{ 15 public: 16 17 Subscriptor() : counter(1) {} 18 19 virtual ~Subscriptor() 20 { 21 counter--; 22 assert(counter == 0); 23 } 24 25 private: 26 mutable int counter; 27}; 28 29template <int dim> struct Function 30{ 31 Function(int i): value(dim + i) {} 32 int value; 33}; 34 35template <int dim> struct Triangulation 36{ 37 38}; 39 40template <int dim> struct Exercise_2_3 41{ 42 enum { DIM = dim }; 43}; 44 45 template <int dim> 46 struct SetUpBase : public Subscriptor 47 { 48 virtual 49 const Function<dim> get_boundary_values () const = 0; 50 51 virtual 52 const Function<dim> get_right_hand_side () const = 0; 53 54 // virtual 55 // void create_coarse_grid (Triangulation<dim> &coarse_grid) const = 0; 56 }; 57 58 template <class Traits, int dim> 59 struct SetUp : public SetUpBase<dim> 60 { 61 SetUp () {}; 62 63 virtual 64 const Function<dim> get_boundary_values () const 65 { return Function<dim>(Traits::DIM); } 66 67 virtual 68 const Function<dim> get_right_hand_side () const 69 { return Function<dim>(Traits::DIM); } 70 71 // virtual 72 // void create_coarse_grid (Triangulation<dim> &coarse_grid) const; 73 74 // static const typename Traits::BoundaryValues boundary_values; 75 // static const typename Traits::RightHandSide right_hand_side; 76 }; 77 78 79void myread(std::istream * in) 80{ 81 char input_str[50] = "\0"; 82 if (in->good()) 83 (*in) >> input_str; 84 std::cout << input_str << std::endl; 85 delete in; 86} 87 88 89 90int main() 91{ 92 /* 93 94 SetUp<Exercise_2_3<1000>, 2> s1a; 95 SetUp<Exercise_2_3<2000>, 1> s2; 96 SetUp<Exercise_2_3<2000>, 2> s2a; 97 return s1->get_boundary_values().value + s1a.get_boundary_values().value + 98 s2.get_boundary_values().value + s2a.get_boundary_values().value + 99 s1->get_right_hand_side().value + s1a.get_right_hand_side().value + 100 s2.get_right_hand_side().value + s2a.get_right_hand_side().value; 101 */ 102 103 SetUp<Exercise_2_3<1000>, 1> * s1 = new SetUp<Exercise_2_3<1000>, 1>(); 104 105 printf("%d\n", s1->get_boundary_values().value); 106 107 ifstream * infile = new ifstream("./template-list-iostream.cc"); 108 109 myread(infile); 110 111 ofstream * outfile = new ofstream("/tmp/xxx.txt"); 112 113 if (outfile->good()) 114 (*outfile) << "hello there" << std::endl; 115 std::cerr << "Reached End" << std::endl; 116 117 delete outfile; 118 119 return 0; 120} 121