Changeset 1713:49d22d34d95f in lemon-0.x for doc/named-param.dox
- Timestamp:
- 10/06/05 12:28:45 (19 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2240
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/named-param.dox
r1709 r1713 22 22 23 23 \code 24 class named _fn24 class namedFn 25 25 { 26 26 int _id; … … 29 29 30 30 public: 31 named _fn() : _id(0), _val(1), _dim(2) {}32 named _fn& id(int p) { _id = p ; return *this; }33 named _fn& val(double p) { _val = p ; return *this; }34 named _fn& dim(int p) { _dim = p ; return *this; }31 namedFn() : _id(0), _val(1), _dim(2) {} 32 namedFn& id(int p) { _id = p ; return *this; } 33 namedFn& val(double p) { _val = p ; return *this; } 34 namedFn& dim(int p) { _dim = p ; return *this; } 35 35 36 36 run() { … … 43 43 The usage is the following. 44 44 45 We have to define a class, let's call it \c named _fn. Let us assume that46 we would like to use a parameter, called \c X. In the \c named _fn class we45 We have to define a class, let's call it \c namedFn. Let us assume that 46 we would like to use a parameter, called \c X. In the \c namedFn class we 47 47 have to define an \c _X attribute, and a function \c X. The function 48 48 expects a parameter with the type of \c _X, and sets the value of … … 56 56 attributes (originally the parameters), initially. If we call function 57 57 \c X, we get a class with the modified parameter value of 58 \c X. Therefore we can modify any parameter-value, independent from the58 \c X. Therefore we can modify any parameter-value, independently from the 59 59 order. To run the algorithm we have to call the <tt>run()</tt> function at the 60 60 end of the row. … … 62 62 Example: 63 63 \code 64 named _fn().id(3).val(2).run();64 namedFn().id(3).val(2).run(); 65 65 \endcode 66 67 \note Although it is a class, namedFn is used pretty much like as it were 68 a function. That it why it is called namedFn and not \c NamedFn. 69 70 \note In fact, the final <tt>.run()</tt> could be made unnecessary if the 71 actual function code were put in the destructor instead. This however would make 72 hard to implement functions with return values, and would also make the 73 implementation of \ref named-templ-func-param "named template parameters" 74 very problematic. Therefore, by convention, <tt>.run()</tt> is used 75 to explicitly execute function having named parameters in Lemon. 76 66 77 67 78 \section traits-classes Traits Classes
Note: See TracChangeset
for help on using the changeset viewer.