Two examples showing a bit more convenient way to implement named parameters.
authoralpar
Wed, 05 Jan 2005 12:26:59 +0000
changeset 1052172ce6c3ac6e
parent 1051 4ebe32765b48
child 1053 90f8696360b2
Two examples showing a bit more convenient way to implement named parameters.
src/work/alpar/named-param-test2.cc
src/work/alpar/named-param-test3.cc
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/work/alpar/named-param-test2.cc	Wed Jan 05 12:26:59 2005 +0000
     1.3 @@ -0,0 +1,54 @@
     1.4 +struct TR 
     1.5 +{
     1.6 +  int a;
     1.7 +  int b;
     1.8 +  int c;
     1.9 +};
    1.10 +
    1.11 +template<class T> struct D
    1.12 +{
    1.13 +  T t;
    1.14 +  
    1.15 +  D(const T &tt) :t(tt) {};
    1.16 +  
    1.17 +  template<class X> struct TA : public T {
    1.18 +    X a;
    1.19 +    TA(const T &t,const X& x) : T(t), a(x) {};
    1.20 +  };
    1.21 +  template<class X> D<TA<X> > setA(const X &x) {
    1.22 +    return D<TA<X> >(TA<X>(this->t,x));
    1.23 +  }
    1.24 +
    1.25 +  template<class X> struct TB : public T {
    1.26 +    X b;
    1.27 +    TB(const T &t,const X& x) : T(t), b(x) {};
    1.28 +  };
    1.29 +
    1.30 +  template<class X> D<TB<X> > setB(const X &x) {
    1.31 +    return D<TB<X> >(TB<X>(this->t,x));
    1.32 +  }
    1.33 +
    1.34 +  template<class X> struct TC : public T {
    1.35 +    X c;
    1.36 +    TC(const T &t,const X& x) : T(t), c(x) {};
    1.37 +  };
    1.38 +
    1.39 +  template<class X> D<TC<X> > setC(const X &x) {
    1.40 +    return D<TC<X> >(TC<X>(this->t,x));
    1.41 +  }
    1.42 +  ~D()
    1.43 +  {
    1.44 +    //Itt csinalunk valamit
    1.45 +  }
    1.46 +};
    1.47 +
    1.48 +D<TR> d() 
    1.49 +{
    1.50 +  return D<TR>(TR());
    1.51 +}
    1.52 +
    1.53 +int main() 
    1.54 +{
    1.55 +  d();
    1.56 +  d().setA(5.5).setB(10).setC(1.5e12);
    1.57 +}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/work/alpar/named-param-test3.cc	Wed Jan 05 12:26:59 2005 +0000
     2.3 @@ -0,0 +1,54 @@
     2.4 +struct TR 
     2.5 +{
     2.6 +  int a;
     2.7 +  int b;
     2.8 +  int c;
     2.9 +};
    2.10 +
    2.11 +template<class T> struct D : public T
    2.12 +{
    2.13 +  
    2.14 +  D(const T &tt) : T(tt) {};
    2.15 +  
    2.16 +  template<class X> struct TA : public T {
    2.17 +    X a;
    2.18 +    TA(const T &t,const X& x) : T(t), a(x) {};
    2.19 +  };
    2.20 +  
    2.21 +  template<class X> D<TA<X> > setA(const X &x) {
    2.22 +    return D<TA<X> >(TA<X>(*this,x));
    2.23 +  }
    2.24 +
    2.25 +  template<class X> struct TB : public T {
    2.26 +    X b;
    2.27 +    TB(const T &t,const X& x) : T(t), b(x) {};
    2.28 +  };
    2.29 +
    2.30 +  template<class X> D<TB<X> > setB(const X &x) {
    2.31 +    return D<TB<X> >(TB<X>(*this,x));
    2.32 +  }
    2.33 +
    2.34 +  template<class X> struct TC : public T {
    2.35 +    X c;
    2.36 +    TC(const T &t,const X& x) : T(t), c(x) {};
    2.37 +  };
    2.38 +
    2.39 +  template<class X> D<TC<X> > setC(const X &x) {
    2.40 +    return D<TC<X> >(TC<X>(*this,x));
    2.41 +  }
    2.42 +  ~D()
    2.43 +  {
    2.44 +    //Itt csinalunk valamit
    2.45 +  }
    2.46 +};
    2.47 +
    2.48 +D<TR> d() 
    2.49 +{
    2.50 +  return D<TR>(TR());
    2.51 +}
    2.52 +
    2.53 +int main() 
    2.54 +{
    2.55 +  d();
    2.56 +  d().setA(5.5).setB(10).setC(1.5e12);
    2.57 +}