One more trial/approach for named params (Under constr.)
authoralpar
Fri, 28 Jan 2005 15:19:34 +0000
changeset 11056777f0b0e7b5
parent 1104 23a54f889272
child 1106 0a7d604a9763
One more trial/approach for named params (Under constr.)
src/work/alpar/named-param-test4.cc
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/work/alpar/named-param-test4.cc	Fri Jan 28 15:19:34 2005 +0000
     1.3 @@ -0,0 +1,78 @@
     1.4 +class AlgorithmDefaultTypes 
     1.5 +{
     1.6 +public:
     1.7 +  typedef int Adat;
     1.8 +};
     1.9 +
    1.10 +template<class T = AlgorithmDefaultTypes>
    1.11 +class AlgorithmTypes : public T 
    1.12 +{
    1.13 +public:
    1.14 +  template<class X>
    1.15 +  class SetAdat : public T { X Adat; };
    1.16 +};
    1.17 +
    1.18 +template<class T = AlgorithmTypes<> >
    1.19 +class AlgorithmDefaultDataFields : public T
    1.20 +{
    1.21 +protected:
    1.22 +  typename T::Adat adat;
    1.23 +};
    1.24 +
    1.25 +template<class T = AlgorithmDefaultDataFields<> >
    1.26 +class Algorithm : public T
    1.27 +{
    1.28 +  int _intAdat;
    1.29 +public:
    1.30 +  Algorithm() {};
    1.31 +  Algorithm(const T &tt) : T(tt) {};
    1.32 +
    1.33 +  template<class X> class _SetAdat : public T {
    1.34 +    protected:
    1.35 +    X adat;
    1.36 +    public:
    1.37 +    _SetAdat() {}; //"Algorithm<>::_SetAdat<double> b;"-hez kell!!!!
    1.38 +                   // De az is rossz!!!!!
    1.39 +    _SetAdat(const T &t,const X& x) : T(t), adat(x) {};
    1.40 +  };
    1.41 +  
    1.42 +  template<class X>
    1.43 +  Algorithm<_SetAdat<X> > setAdat(const X &x) {
    1.44 +    return Algorithm<_SetAdat<X> >(_SetAdat<X>(*this,x));
    1.45 +  }
    1.46 +  
    1.47 +  Algorithm &setIntAdat(int i) {_intAdat=i;return *this;}
    1.48 +  //vagy:
    1.49 +  Algorithm &intAdat(int i) {_intAdat=i;return *this;}
    1.50 +  
    1.51 +  typename T::Adat run()
    1.52 +  {
    1.53 +    //Itt csinalunk valamit
    1.54 +    return typename T::Adat();    
    1.55 +  }
    1.56 +  ~Algorithm()
    1.57 +  {
    1.58 +    //Itt nem csinalunk semmit
    1.59 +  }
    1.60 +};
    1.61 +
    1.62 +Algorithm<> algorithm() 
    1.63 +{
    1.64 +  return Algorithm<>();
    1.65 +}
    1.66 +
    1.67 +int main() 
    1.68 +{
    1.69 +  Algorithm<> a;
    1.70 +
    1.71 +  Algorithm<>::_SetAdat<double> b; b=b;//Ez itt nem az, amit szeretnenk!!! 
    1.72 +
    1.73 +  Algorithm<>::SetAdat<double> c; c=c; //Ez itt nem az, amit szeretnenk!!!
    1.74 +
    1.75 +  a.run();
    1.76 +  //  b.run();
    1.77 +  //  c.run();
    1.78 +  
    1.79 +  algorithm().run();
    1.80 +  algorithm().setAdat(5.2).run();
    1.81 +}