src/work/alpar/named-param-test.cc
changeset 1365 c280de819a73
parent 1364 ee5959aa4410
child 1366 d00b85f8be45
     1.1 --- a/src/work/alpar/named-param-test.cc	Sun Apr 17 18:57:22 2005 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,145 +0,0 @@
     1.4 -// -*- mode:C++ -*-
     1.5 -
     1.6 -//////////////////////////////////////////////////////////////////////
     1.7 -// Named "function" parameters
     1.8 -//////////////////////////////////////////////////////////////////////
     1.9 -
    1.10 -class named_fn 
    1.11 -{
    1.12 -  int _id;
    1.13 -  double _val;
    1.14 -  int _dim;
    1.15 -  
    1.16 -  public:
    1.17 -  named_fn() : _id(0), _val(1), _dim(2) {}
    1.18 -  named_fn& id(int p)     { _id  = p ; return *this; }
    1.19 -  named_fn& val(double p) { _val = p ; return *this; }
    1.20 -  named_fn& dim(int p)    { _dim = p ; return *this; }
    1.21 -
    1.22 -  ~named_fn() {
    1.23 -    //Itt van maga az algoritmus
    1.24 -  }
    1.25 -};
    1.26 -
    1.27 -//Hasznalat:
    1.28 -//named_fn().id(3);
    1.29 -//named_fn().id(3).val(2);
    1.30 -//named_fn().dim(4).id(3);
    1.31 -
    1.32 -
    1.33 -//////////////////////////////////////////////////////////////////////
    1.34 -// Named class template parameters (A)
    1.35 -//////////////////////////////////////////////////////////////////////
    1.36 -
    1.37 -template<class A=int,class B=double>
    1.38 -class Named_T
    1.39 -{
    1.40 -public:
    1.41 -
    1.42 -  typedef A Atype;
    1.43 -  typedef B Btype;
    1.44 -
    1.45 -  template <class T> class SetAType : public Named_T<T,Btype> { };
    1.46 -  template <class T> class SetBType : public Named_T<Atype,T> { };
    1.47 -};
    1.48 -
    1.49 -// Named_T<>::SetAType<double>::SetBType<double>
    1.50 -
    1.51 -//////////////////////////////////////////////////////////////////////
    1.52 -// Named class template parameters (A)
    1.53 -//////////////////////////////////////////////////////////////////////
    1.54 -
    1.55 -struct _NTR 
    1.56 -{
    1.57 -  typedef int Atype;
    1.58 -  typedef double Btype;
    1.59 -};
    1.60 -
    1.61 -template<class TR=_NTR>
    1.62 -class Named_TR
    1.63 -{
    1.64 -public:
    1.65 -
    1.66 -  typedef typename TR::Atype Atype;
    1.67 -  typedef typename TR::Btype Btype;
    1.68 -
    1.69 -  Atype a;
    1.70 -  Btype b;
    1.71 -  
    1.72 -  template <class T>
    1.73 -  struct ATR : public TR {
    1.74 -    typedef T Atype;
    1.75 -  };
    1.76 -
    1.77 -  template <class T>
    1.78 -  class SetAType : public Named_TR<ATR<T> > { };
    1.79 -
    1.80 -  template <class T>
    1.81 -  struct BTR : public TR {
    1.82 -    typedef T Btype;
    1.83 -  };
    1.84 -  template <class T>
    1.85 -  class SetBType : public Named_TR<BTR<T> > { };
    1.86 -
    1.87 -  Named_TR() {};
    1.88 -  Named_TR<TR> &setA(Atype _a) { a=_a; return *this;}
    1.89 -  Named_TR<TR> &setB(Btype _b) { b=_b; return *this;}
    1.90 -
    1.91 -  void run() {
    1.92 -    // itt az algoritmus
    1.93 -  }
    1.94 -
    1.95 -  //////////////////////////////////////////////////////////////////////
    1.96 -  template<class T>
    1.97 -  SetAType<T> SETA(T t) { SetAType<T> r; r.a=t; r.b=b; return r;}
    1.98 -  template<class T>
    1.99 -  SetBType<T> SETB(T t) { SetBType<T> r; r.a=a; r.b=t; return r;}
   1.100 -};
   1.101 -
   1.102 -// Hasznalat:
   1.103 -// 1.
   1.104 -//   Named_TR<>::SetAType<double> nt;
   1.105 -//   Named_TR<>::SetBType<double>::SetAType<double> nt2;
   1.106 -//   nt2.setA(5).setB(6).run();
   1.107 -// 2.
   1.108 -//   double x;
   1.109 -//   Named_TR<>().SETA(5.2).SETB(x).run();
   1.110 -// 3. 
   1.111 -//   struct MyTr : public _NTR { typedef float Btype; };
   1.112 -//   int main() 
   1.113 -//   {
   1.114 -//     Named_TR<MyTr> d2; d2=d2;
   1.115 -//   }
   1.116 -
   1.117 -
   1.118 -// Sajnos ezt csak a fuggvenyen kivul lehet deklaralni:
   1.119 -struct MyTr : public _NTR { typedef float Btype; };
   1.120 -
   1.121 -typedef Named_T<> Named_TN;
   1.122 -
   1.123 -int main()
   1.124 -{
   1.125 -
   1.126 -  Named_T<> a;a=a;
   1.127 -  Named_T<>::SetAType<double> b;b=b;
   1.128 -  Named_T<>::SetAType<double>::SetBType<int> c;c=c;
   1.129 -
   1.130 -  Named_TR<> a2;a2=a2;
   1.131 -  Named_TR<>::SetAType<double> b2;b2=b2;
   1.132 -  Named_TR<>::SetAType<double>::SetBType<int> c2;c2=c2;
   1.133 -
   1.134 -  //De igy is lehet:
   1.135 -  Named_TR<MyTr> d2; d2=d2;
   1.136 -
   1.137 -  named_fn().id(3);
   1.138 -  named_fn().id(3).val(2);
   1.139 -  named_fn().dim(4).id(3);
   1.140 -
   1.141 -   Named_TR<>::SetAType<double> nt;
   1.142 -   Named_TR<>::SetBType<double>::SetAType<double> nt2;
   1.143 -   nt2.setA(5).setB(6).run();
   1.144 -
   1.145 -   double x;
   1.146 -   Named_TR<>().SETA(5.2).SETB(x).run();
   1.147 -}
   1.148 -