COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/alpar/named-param-test4.cc @ 1278:4abea330614d

Last change on this file since 1278:4abea330614d was 1203:14f951664a63, checked in by Alpar Juttner, 20 years ago

Nothing special

File size: 2.1 KB
RevLine 
[1203]1///\file
2///Named template study
3
4///\e
5
6///\e
7///
[1105]8class AlgorithmDefaultTypes
9{
10public:
[1203]11///\e
12
13///\e
14///
[1105]15  typedef int Adat;
16};
17
[1203]18///\e
19
20///\e
21///
[1105]22template<class T = AlgorithmDefaultTypes>
23class AlgorithmTypes : public T
24{
25public:
[1203]26///\e
27
28///\e
29///
[1105]30  template<class X>
31  class SetAdat : public T { X Adat; };
32};
33
[1203]34///\e
35
36///\e
37///
[1105]38template<class T = AlgorithmTypes<> >
39class AlgorithmDefaultDataFields : public T
40{
41protected:
[1203]42///\e
43
44///\e
45///
46  typedef T TypeTraits; //Jo ez a nev?
47protected:
48///\e
49
50///\e
51///
[1105]52  typename T::Adat adat;
53};
54
[1203]55///\e
56
57///\e
58///
[1105]59template<class T = AlgorithmDefaultDataFields<> >
60class Algorithm : public T
61{
62  int _intAdat;
63public:
64  Algorithm() {};
65  Algorithm(const T &tt) : T(tt) {};
66
67  template<class X> class _SetAdat : public T {
68    protected:
69    X adat;
70    public:
[1203]71    typedef X Adat;
[1105]72    _SetAdat() {}; //"Algorithm<>::_SetAdat<double> b;"-hez kell!!!!
73                   // De az is rossz!!!!!
74    _SetAdat(const T &t,const X& x) : T(t), adat(x) {};
75  };
76 
[1203]77 ///\name Funtion Named Parameters
78 
79  ///@{
80
81  ///\e
82 
83  ///\e
84  ///
[1105]85  template<class X>
86  Algorithm<_SetAdat<X> > setAdat(const X &x) {
87    return Algorithm<_SetAdat<X> >(_SetAdat<X>(*this,x));
88  }
[1203]89
90  ///@}
91  ///\name Named Parameters
[1105]92 
[1203]93  ///@{
94
95  ///\e
96 
97  ///\e
98  ///
99  template<class X>
100  class SetAdat :
101    public Algorithm<AlgorithmDefaultDataFields<
102    typename T::TypeTraits::template SetAdat<X> > >
103  {};
104 
105  ///@} 
106
107///\e
108
109///\e
110///
[1105]111  Algorithm &setIntAdat(int i) {_intAdat=i;return *this;}
112  //vagy:
[1203]113///Vagy
114
115///Vagy...
116///
[1105]117  Algorithm &intAdat(int i) {_intAdat=i;return *this;}
118 
[1203]119  //Maga az algoritmus!!!!!!!
120///\e
121
122///\e
123///
[1105]124  typename T::Adat run()
125  {
126    //Itt csinalunk valamit
[1203]127    return adat;   
[1105]128  }
[1203]129
[1105]130  ~Algorithm()
131  {
132    //Itt nem csinalunk semmit
133  }
134};
135
[1203]136///\e
137
138///\e
139///
[1105]140Algorithm<> algorithm()
141{
142  return Algorithm<>();
143}
144
145int main()
146{
147  Algorithm<> a;
[1203]148  a.run();
[1105]149
[1203]150//   Algorithm<>::_SetAdat<double> b; b=b;//Ez itt nem az, amit szeretnenk!!!
151//   //  b.run();
152 
153  Algorithm<>::SetAdat<double> c; //Algorithm<>::Adat<double> c; jobb vo'na
154  c.run();
[1105]155
156  algorithm().run();
157  algorithm().setAdat(5.2).run();
158}
Note: See TracBrowser for help on using the repository browser.