diff -r ee5959aa4410 -r c280de819a73 src/work/alpar/named-param-test.cc --- a/src/work/alpar/named-param-test.cc Sun Apr 17 18:57:22 2005 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,145 +0,0 @@ -// -*- mode:C++ -*- - -////////////////////////////////////////////////////////////////////// -// Named "function" parameters -////////////////////////////////////////////////////////////////////// - -class named_fn -{ - int _id; - double _val; - int _dim; - - public: - named_fn() : _id(0), _val(1), _dim(2) {} - named_fn& id(int p) { _id = p ; return *this; } - named_fn& val(double p) { _val = p ; return *this; } - named_fn& dim(int p) { _dim = p ; return *this; } - - ~named_fn() { - //Itt van maga az algoritmus - } -}; - -//Hasznalat: -//named_fn().id(3); -//named_fn().id(3).val(2); -//named_fn().dim(4).id(3); - - -////////////////////////////////////////////////////////////////////// -// Named class template parameters (A) -////////////////////////////////////////////////////////////////////// - -template -class Named_T -{ -public: - - typedef A Atype; - typedef B Btype; - - template class SetAType : public Named_T { }; - template class SetBType : public Named_T { }; -}; - -// Named_T<>::SetAType::SetBType - -////////////////////////////////////////////////////////////////////// -// Named class template parameters (A) -////////////////////////////////////////////////////////////////////// - -struct _NTR -{ - typedef int Atype; - typedef double Btype; -}; - -template -class Named_TR -{ -public: - - typedef typename TR::Atype Atype; - typedef typename TR::Btype Btype; - - Atype a; - Btype b; - - template - struct ATR : public TR { - typedef T Atype; - }; - - template - class SetAType : public Named_TR > { }; - - template - struct BTR : public TR { - typedef T Btype; - }; - template - class SetBType : public Named_TR > { }; - - Named_TR() {}; - Named_TR &setA(Atype _a) { a=_a; return *this;} - Named_TR &setB(Btype _b) { b=_b; return *this;} - - void run() { - // itt az algoritmus - } - - ////////////////////////////////////////////////////////////////////// - template - SetAType SETA(T t) { SetAType r; r.a=t; r.b=b; return r;} - template - SetBType SETB(T t) { SetBType r; r.a=a; r.b=t; return r;} -}; - -// Hasznalat: -// 1. -// Named_TR<>::SetAType nt; -// Named_TR<>::SetBType::SetAType nt2; -// nt2.setA(5).setB(6).run(); -// 2. -// double x; -// Named_TR<>().SETA(5.2).SETB(x).run(); -// 3. -// struct MyTr : public _NTR { typedef float Btype; }; -// int main() -// { -// Named_TR d2; d2=d2; -// } - - -// Sajnos ezt csak a fuggvenyen kivul lehet deklaralni: -struct MyTr : public _NTR { typedef float Btype; }; - -typedef Named_T<> Named_TN; - -int main() -{ - - Named_T<> a;a=a; - Named_T<>::SetAType b;b=b; - Named_T<>::SetAType::SetBType c;c=c; - - Named_TR<> a2;a2=a2; - Named_TR<>::SetAType b2;b2=b2; - Named_TR<>::SetAType::SetBType c2;c2=c2; - - //De igy is lehet: - Named_TR d2; d2=d2; - - named_fn().id(3); - named_fn().id(3).val(2); - named_fn().dim(4).id(3); - - Named_TR<>::SetAType nt; - Named_TR<>::SetBType::SetAType nt2; - nt2.setA(5).setB(6).run(); - - double x; - Named_TR<>().SETA(5.2).SETB(x).run(); -} -