[Lemon-commits] [lemon_svn] alpar: r1446 - hugo/trunk/src/work/alpar

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:45:30 CET 2006


Author: alpar
Date: Wed Jan  5 13:26:59 2005
New Revision: 1446

Added:
   hugo/trunk/src/work/alpar/named-param-test2.cc
   hugo/trunk/src/work/alpar/named-param-test3.cc

Log:
Two examples showing a bit more convenient way to implement named parameters. 


Added: hugo/trunk/src/work/alpar/named-param-test2.cc
==============================================================================
--- (empty file)
+++ hugo/trunk/src/work/alpar/named-param-test2.cc	Wed Jan  5 13:26:59 2005
@@ -0,0 +1,54 @@
+struct TR 
+{
+  int a;
+  int b;
+  int c;
+};
+
+template<class T> struct D
+{
+  T t;
+  
+  D(const T &tt) :t(tt) {};
+  
+  template<class X> struct TA : public T {
+    X a;
+    TA(const T &t,const X& x) : T(t), a(x) {};
+  };
+  template<class X> D<TA<X> > setA(const X &x) {
+    return D<TA<X> >(TA<X>(this->t,x));
+  }
+
+  template<class X> struct TB : public T {
+    X b;
+    TB(const T &t,const X& x) : T(t), b(x) {};
+  };
+
+  template<class X> D<TB<X> > setB(const X &x) {
+    return D<TB<X> >(TB<X>(this->t,x));
+  }
+
+  template<class X> struct TC : public T {
+    X c;
+    TC(const T &t,const X& x) : T(t), c(x) {};
+  };
+
+  template<class X> D<TC<X> > setC(const X &x) {
+    return D<TC<X> >(TC<X>(this->t,x));
+  }
+  ~D()
+  {
+    //Itt csinalunk valamit
+  }
+};
+
+D<TR> d() 
+{
+  return D<TR>(TR());
+}
+
+int main() 
+{
+  d();
+  d().setA(5.5).setB(10).setC(1.5e12);
+}

Added: hugo/trunk/src/work/alpar/named-param-test3.cc
==============================================================================
--- (empty file)
+++ hugo/trunk/src/work/alpar/named-param-test3.cc	Wed Jan  5 13:26:59 2005
@@ -0,0 +1,54 @@
+struct TR 
+{
+  int a;
+  int b;
+  int c;
+};
+
+template<class T> struct D : public T
+{
+  
+  D(const T &tt) : T(tt) {};
+  
+  template<class X> struct TA : public T {
+    X a;
+    TA(const T &t,const X& x) : T(t), a(x) {};
+  };
+  
+  template<class X> D<TA<X> > setA(const X &x) {
+    return D<TA<X> >(TA<X>(*this,x));
+  }
+
+  template<class X> struct TB : public T {
+    X b;
+    TB(const T &t,const X& x) : T(t), b(x) {};
+  };
+
+  template<class X> D<TB<X> > setB(const X &x) {
+    return D<TB<X> >(TB<X>(*this,x));
+  }
+
+  template<class X> struct TC : public T {
+    X c;
+    TC(const T &t,const X& x) : T(t), c(x) {};
+  };
+
+  template<class X> D<TC<X> > setC(const X &x) {
+    return D<TC<X> >(TC<X>(*this,x));
+  }
+  ~D()
+  {
+    //Itt csinalunk valamit
+  }
+};
+
+D<TR> d() 
+{
+  return D<TR>(TR());
+}
+
+int main() 
+{
+  d();
+  d().setA(5.5).setB(10).setC(1.5e12);
+}



More information about the Lemon-commits mailing list