# HG changeset patch # User alpar # Date 1104928019 0 # Node ID 172ce6c3ac6ea8f5b13fbd81968a6d71cb842368 # Parent 4ebe32765b48f1a5b8e619f9a5f9ebcc3a0a9842 Two examples showing a bit more convenient way to implement named parameters. diff -r 4ebe32765b48 -r 172ce6c3ac6e src/work/alpar/named-param-test2.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/alpar/named-param-test2.cc Wed Jan 05 12:26:59 2005 +0000 @@ -0,0 +1,54 @@ +struct TR +{ + int a; + int b; + int c; +}; + +template struct D +{ + T t; + + D(const T &tt) :t(tt) {}; + + template struct TA : public T { + X a; + TA(const T &t,const X& x) : T(t), a(x) {}; + }; + template D > setA(const X &x) { + return D >(TA(this->t,x)); + } + + template struct TB : public T { + X b; + TB(const T &t,const X& x) : T(t), b(x) {}; + }; + + template D > setB(const X &x) { + return D >(TB(this->t,x)); + } + + template struct TC : public T { + X c; + TC(const T &t,const X& x) : T(t), c(x) {}; + }; + + template D > setC(const X &x) { + return D >(TC(this->t,x)); + } + ~D() + { + //Itt csinalunk valamit + } +}; + +D d() +{ + return D(TR()); +} + +int main() +{ + d(); + d().setA(5.5).setB(10).setC(1.5e12); +} diff -r 4ebe32765b48 -r 172ce6c3ac6e src/work/alpar/named-param-test3.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/alpar/named-param-test3.cc Wed Jan 05 12:26:59 2005 +0000 @@ -0,0 +1,54 @@ +struct TR +{ + int a; + int b; + int c; +}; + +template struct D : public T +{ + + D(const T &tt) : T(tt) {}; + + template struct TA : public T { + X a; + TA(const T &t,const X& x) : T(t), a(x) {}; + }; + + template D > setA(const X &x) { + return D >(TA(*this,x)); + } + + template struct TB : public T { + X b; + TB(const T &t,const X& x) : T(t), b(x) {}; + }; + + template D > setB(const X &x) { + return D >(TB(*this,x)); + } + + template struct TC : public T { + X c; + TC(const T &t,const X& x) : T(t), c(x) {}; + }; + + template D > setC(const X &x) { + return D >(TC(*this,x)); + } + ~D() + { + //Itt csinalunk valamit + } +}; + +D d() +{ + return D(TR()); +} + +int main() +{ + d(); + d().setA(5.5).setB(10).setC(1.5e12); +}