COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/alpar/named-param-test4.cc @ 1105:6777f0b0e7b5

Last change on this file since 1105:6777f0b0e7b5 was 1105:6777f0b0e7b5, checked in by Alpar Juttner, 20 years ago

One more trial/approach for named params (Under constr.)

File size: 1.5 KB
Line 
1class AlgorithmDefaultTypes
2{
3public:
4  typedef int Adat;
5};
6
7template<class T = AlgorithmDefaultTypes>
8class AlgorithmTypes : public T
9{
10public:
11  template<class X>
12  class SetAdat : public T { X Adat; };
13};
14
15template<class T = AlgorithmTypes<> >
16class AlgorithmDefaultDataFields : public T
17{
18protected:
19  typename T::Adat adat;
20};
21
22template<class T = AlgorithmDefaultDataFields<> >
23class Algorithm : public T
24{
25  int _intAdat;
26public:
27  Algorithm() {};
28  Algorithm(const T &tt) : T(tt) {};
29
30  template<class X> class _SetAdat : public T {
31    protected:
32    X adat;
33    public:
34    _SetAdat() {}; //"Algorithm<>::_SetAdat<double> b;"-hez kell!!!!
35                   // De az is rossz!!!!!
36    _SetAdat(const T &t,const X& x) : T(t), adat(x) {};
37  };
38 
39  template<class X>
40  Algorithm<_SetAdat<X> > setAdat(const X &x) {
41    return Algorithm<_SetAdat<X> >(_SetAdat<X>(*this,x));
42  }
43 
44  Algorithm &setIntAdat(int i) {_intAdat=i;return *this;}
45  //vagy:
46  Algorithm &intAdat(int i) {_intAdat=i;return *this;}
47 
48  typename T::Adat run()
49  {
50    //Itt csinalunk valamit
51    return typename T::Adat();   
52  }
53  ~Algorithm()
54  {
55    //Itt nem csinalunk semmit
56  }
57};
58
59Algorithm<> algorithm()
60{
61  return Algorithm<>();
62}
63
64int main()
65{
66  Algorithm<> a;
67
68  Algorithm<>::_SetAdat<double> b; b=b;//Ez itt nem az, amit szeretnenk!!!
69
70  Algorithm<>::SetAdat<double> c; c=c; //Ez itt nem az, amit szeretnenk!!!
71
72  a.run();
73  //  b.run();
74  //  c.run();
75 
76  algorithm().run();
77  algorithm().setAdat(5.2).run();
78}
Note: See TracBrowser for help on using the repository browser.